js.documents 1.61.0 → 1.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/README.md +120 -47
  2. package/dist/{blr-types-CYYC3yYU.d.cts → blr-types-DVgO1DQ9.d.cts} +1 -1
  3. package/dist/{blr-types-CYYC3yYU.d.ts → blr-types-DVgO1DQ9.d.ts} +1 -1
  4. package/dist/convert/capability.cjs +1 -0
  5. package/dist/convert/capability.d.cts +1 -1
  6. package/dist/convert/capability.d.ts +1 -1
  7. package/dist/convert/capability.js +1 -0
  8. package/dist/convert/convert.cjs +92 -38
  9. package/dist/convert/convert.d.cts +11 -4
  10. package/dist/convert/convert.d.ts +11 -4
  11. package/dist/convert/convert.js +93 -39
  12. package/dist/convert/local.cjs +15 -2
  13. package/dist/convert/local.js +15 -2
  14. package/dist/convert/port.d.cts +8 -4
  15. package/dist/convert/port.d.ts +8 -4
  16. package/dist/edit/docx/content.cjs +75 -13
  17. package/dist/edit/docx/content.d.cts +8 -2
  18. package/dist/edit/docx/content.d.ts +8 -2
  19. package/dist/edit/docx/content.js +75 -13
  20. package/dist/edit/docx/paragraph.cjs +14 -0
  21. package/dist/edit/docx/paragraph.d.cts +5 -0
  22. package/dist/edit/docx/paragraph.d.ts +5 -0
  23. package/dist/edit/docx/paragraph.js +14 -0
  24. package/dist/edit/docx/run.cjs +1 -1
  25. package/dist/edit/docx/run.js +1 -1
  26. package/dist/edit/docx/table.cjs +41 -0
  27. package/dist/edit/docx/table.d.cts +7 -1
  28. package/dist/edit/docx/table.d.ts +7 -1
  29. package/dist/edit/docx/table.js +42 -1
  30. package/dist/edit/geometry.cjs +38 -0
  31. package/dist/edit/geometry.d.cts +7 -0
  32. package/dist/edit/geometry.d.ts +7 -0
  33. package/dist/edit/geometry.js +36 -0
  34. package/dist/edit/odg/content.cjs +15 -12
  35. package/dist/edit/odg/content.js +15 -12
  36. package/dist/edit/odg/editor.d.cts +1 -1
  37. package/dist/edit/odg/editor.d.ts +1 -1
  38. package/dist/edit/odg/page.d.cts +3 -3
  39. package/dist/edit/odg/page.d.ts +3 -3
  40. package/dist/edit/odg/vector.cjs +22 -13
  41. package/dist/edit/odg/vector.d.cts +1 -1
  42. package/dist/edit/odg/vector.d.ts +1 -1
  43. package/dist/edit/odg/vector.js +23 -14
  44. package/dist/edit/odp/content.cjs +15 -0
  45. package/dist/edit/odp/content.js +16 -1
  46. package/dist/edit/odp/editor.d.cts +1 -1
  47. package/dist/edit/odp/editor.d.ts +1 -1
  48. package/dist/edit/odp/image.d.cts +1 -1
  49. package/dist/edit/odp/image.d.ts +1 -1
  50. package/dist/edit/odp/shape.cjs +11 -30
  51. package/dist/edit/odp/shape.d.cts +2 -2
  52. package/dist/edit/odp/shape.d.ts +2 -2
  53. package/dist/edit/odp/shape.js +13 -33
  54. package/dist/edit/odp/slide.cjs +11 -0
  55. package/dist/edit/odp/slide.d.cts +14 -4
  56. package/dist/edit/odp/slide.d.ts +14 -4
  57. package/dist/edit/odp/slide.js +12 -1
  58. package/dist/edit/odt/content.cjs +56 -16
  59. package/dist/edit/odt/content.d.cts +4 -2
  60. package/dist/edit/odt/content.d.ts +4 -2
  61. package/dist/edit/odt/content.js +56 -17
  62. package/dist/edit/odt/editor.d.cts +1 -1
  63. package/dist/edit/odt/editor.d.ts +1 -1
  64. package/dist/edit/odt/table.cjs +36 -0
  65. package/dist/edit/odt/table.d.cts +1 -36
  66. package/dist/edit/odt/table.d.ts +1 -36
  67. package/dist/edit/odt/table.js +37 -1
  68. package/dist/edit/pptx/content.cjs +71 -3
  69. package/dist/edit/pptx/content.js +71 -3
  70. package/dist/edit/pptx/editor.d.cts +1 -1
  71. package/dist/edit/pptx/editor.d.ts +1 -1
  72. package/dist/edit/pptx/image.d.cts +1 -1
  73. package/dist/edit/pptx/image.d.ts +1 -1
  74. package/dist/edit/pptx/shape.cjs +23 -1
  75. package/dist/edit/pptx/shape.d.cts +2 -2
  76. package/dist/edit/pptx/shape.d.ts +2 -2
  77. package/dist/edit/pptx/shape.js +23 -3
  78. package/dist/edit/pptx/slide.cjs +10 -1
  79. package/dist/edit/pptx/slide.d.cts +11 -4
  80. package/dist/edit/pptx/slide.d.ts +11 -4
  81. package/dist/edit/pptx/slide.js +10 -1
  82. package/dist/edit/pptx/table.cjs +136 -0
  83. package/dist/edit/pptx/table.d.cts +2 -0
  84. package/dist/edit/pptx/table.d.ts +2 -0
  85. package/dist/edit/pptx/table.js +131 -0
  86. package/dist/firebird/backup.d.cts +1 -1
  87. package/dist/firebird/backup.d.ts +1 -1
  88. package/dist/firebird/blr-types.cjs +2 -2
  89. package/dist/firebird/blr-types.d.cts +1 -1
  90. package/dist/firebird/blr-types.d.ts +1 -1
  91. package/dist/firebird/blr-types.js +2 -2
  92. package/dist/firebird/data.cjs +68 -14
  93. package/dist/firebird/data.d.cts +1 -1
  94. package/dist/firebird/data.d.ts +1 -1
  95. package/dist/firebird/data.js +68 -14
  96. package/dist/firebird/schema.cjs +13 -1
  97. package/dist/firebird/schema.d.cts +1 -1
  98. package/dist/firebird/schema.d.ts +1 -1
  99. package/dist/firebird/schema.js +13 -1
  100. package/dist/fonts/obfuscation.cjs +50 -0
  101. package/dist/fonts/obfuscation.d.cts +9 -0
  102. package/dist/fonts/obfuscation.d.ts +9 -0
  103. package/dist/fonts/obfuscation.js +46 -0
  104. package/dist/fonts/odf.cjs +86 -0
  105. package/dist/fonts/odf.d.cts +9 -0
  106. package/dist/fonts/odf.d.ts +9 -0
  107. package/dist/fonts/odf.js +84 -0
  108. package/dist/fonts/ooxml.cjs +129 -0
  109. package/dist/fonts/ooxml.d.cts +9 -0
  110. package/dist/fonts/ooxml.d.ts +9 -0
  111. package/dist/fonts/ooxml.js +127 -0
  112. package/dist/fonts/registry.cjs +18 -0
  113. package/dist/fonts/registry.d.cts +2 -0
  114. package/dist/fonts/registry.d.ts +2 -0
  115. package/dist/fonts/registry.js +16 -0
  116. package/dist/{geometry-DvwdrIij.d.cts → geometry-DaJr8yQW.d.cts} +2 -2
  117. package/dist/{geometry-DvwdrIij.d.ts → geometry-DaJr8yQW.d.ts} +2 -2
  118. package/dist/hsqldb/binary-script.cjs +154 -0
  119. package/dist/hsqldb/binary-script.d.cts +15 -0
  120. package/dist/hsqldb/binary-script.d.ts +15 -0
  121. package/dist/hsqldb/binary-script.js +151 -0
  122. package/dist/hsqldb/cache.cjs +18 -11
  123. package/dist/hsqldb/cache.d.cts +9 -4
  124. package/dist/hsqldb/cache.d.ts +9 -4
  125. package/dist/hsqldb/cache.js +18 -11
  126. package/dist/hsqldb/rowformat.cjs +60 -16
  127. package/dist/hsqldb/rowformat.d.cts +2 -21
  128. package/dist/hsqldb/rowformat.d.ts +2 -21
  129. package/dist/hsqldb/rowformat.js +60 -17
  130. package/dist/{image-BZDy72Jb.d.cts → image-7snmKIxn.d.cts} +1 -1
  131. package/dist/{image-B-xQWYYS.d.ts → image-Cs8xF753.d.ts} +1 -1
  132. package/dist/{image-CeqwL-Qs.d.ts → image-DHcA9kaK.d.ts} +1 -1
  133. package/dist/{image-DWX6cNOD.d.cts → image-M5SezZVI.d.cts} +1 -1
  134. package/dist/index.cjs +86 -3
  135. package/dist/index.d.cts +33 -21
  136. package/dist/index.d.ts +33 -21
  137. package/dist/index.js +18 -5
  138. package/dist/layout/cell-typing.cjs +209 -0
  139. package/dist/layout/cell-typing.d.cts +22 -0
  140. package/dist/layout/cell-typing.d.ts +22 -0
  141. package/dist/layout/cell-typing.js +208 -0
  142. package/dist/layout/drawing.cjs +193 -17
  143. package/dist/layout/drawing.js +193 -17
  144. package/dist/layout/engine.cjs +46 -29
  145. package/dist/layout/engine.d.cts +0 -2
  146. package/dist/layout/engine.d.ts +0 -2
  147. package/dist/layout/engine.js +47 -30
  148. package/dist/layout/lattice.cjs +139 -0
  149. package/dist/layout/lattice.d.cts +20 -0
  150. package/dist/layout/lattice.d.ts +20 -0
  151. package/dist/layout/lattice.js +135 -0
  152. package/dist/layout/reconstruct.cjs +176 -113
  153. package/dist/layout/reconstruct.d.cts +2 -0
  154. package/dist/layout/reconstruct.d.ts +2 -0
  155. package/dist/layout/reconstruct.js +173 -110
  156. package/dist/layout/shared.cjs +52 -0
  157. package/dist/layout/shared.d.cts +4 -2
  158. package/dist/layout/shared.d.ts +4 -2
  159. package/dist/layout/shared.js +51 -1
  160. package/dist/layout/sheets.cjs +45 -11
  161. package/dist/layout/sheets.js +46 -12
  162. package/dist/layout/slides.cjs +7 -7
  163. package/dist/layout/slides.d.cts +0 -3
  164. package/dist/layout/slides.d.ts +0 -3
  165. package/dist/layout/slides.js +7 -7
  166. package/dist/markdown/write.cjs +19 -6
  167. package/dist/markdown/write.js +19 -6
  168. package/dist/mathml/layout.cjs +2 -2
  169. package/dist/mathml/layout.d.cts +1 -1
  170. package/dist/mathml/layout.d.ts +1 -1
  171. package/dist/mathml/layout.js +2 -2
  172. package/dist/model/embedded-drawing.cjs +32 -0
  173. package/dist/model/embedded-drawing.d.cts +8 -0
  174. package/dist/model/embedded-drawing.d.ts +8 -0
  175. package/dist/model/embedded-drawing.js +30 -0
  176. package/dist/model/formula.cjs +31 -0
  177. package/dist/model/formula.d.cts +6 -6
  178. package/dist/model/formula.d.ts +6 -6
  179. package/dist/model/formula.js +27 -0
  180. package/dist/model/geometry.d.cts +1 -1
  181. package/dist/model/geometry.d.ts +1 -1
  182. package/dist/model/paint-order.cjs +15 -0
  183. package/dist/model/paint-order.d.cts +14 -0
  184. package/dist/model/paint-order.d.ts +14 -0
  185. package/dist/model/paint-order.js +14 -0
  186. package/dist/odb/components.cjs +12 -0
  187. package/dist/odb/components.d.cts +6 -0
  188. package/dist/odb/components.d.ts +6 -0
  189. package/dist/odb/components.js +10 -0
  190. package/dist/odb/read.cjs +11 -7
  191. package/dist/odb/read.d.cts +3 -2
  192. package/dist/odb/read.d.ts +3 -2
  193. package/dist/odb/read.js +11 -7
  194. package/dist/odf/formula/detect.cjs +86 -18
  195. package/dist/odf/formula/detect.d.cts +10 -6
  196. package/dist/odf/formula/detect.d.ts +10 -6
  197. package/dist/odf/formula/detect.js +86 -19
  198. package/dist/odf/formula/read.cjs +4 -16
  199. package/dist/odf/formula/read.d.cts +4 -8
  200. package/dist/odf/formula/read.d.ts +4 -8
  201. package/dist/odf/formula/read.js +5 -17
  202. package/dist/odf/odp/read.cjs +9 -19
  203. package/dist/odf/odp/read.d.cts +2 -7
  204. package/dist/odf/odp/read.d.ts +2 -7
  205. package/dist/odf/odp/read.js +10 -20
  206. package/dist/odf/odt/read.cjs +63 -23
  207. package/dist/odf/odt/read.d.cts +2 -7
  208. package/dist/odf/odt/read.d.ts +2 -7
  209. package/dist/odf/odt/read.js +64 -24
  210. package/dist/omml/write.cjs +258 -0
  211. package/dist/omml/write.d.cts +2 -0
  212. package/dist/omml/write.d.ts +2 -0
  213. package/dist/omml/write.js +256 -0
  214. package/dist/registry-CrSqLIcn.d.ts +19 -0
  215. package/dist/registry-CtPhMD0f.d.cts +19 -0
  216. package/dist/rowformat-Cl2exlEh.d.cts +25 -0
  217. package/dist/rowformat-Cl2exlEh.d.ts +25 -0
  218. package/dist/{schema-Acco3Ezi.d.cts → schema-BeR_KJ0X.d.cts} +3 -1
  219. package/dist/{schema-VkAA6pF5.d.ts → schema-CSKwSb_v.d.ts} +3 -1
  220. package/dist/{shape-BUfjw5eZ.d.cts → shape-BhkP6HB8.d.cts} +6 -2
  221. package/dist/{shape-CTkl6kt8.d.ts → shape-BkVcwPcf.d.ts} +6 -2
  222. package/dist/{shape-BfN3m52m.d.ts → shape-CVXedeL7.d.ts} +3 -2
  223. package/dist/{shape-CN2ycxOo.d.cts → shape-CXZ6fejV.d.cts} +3 -2
  224. package/dist/table-C3CPZ--2.d.cts +35 -0
  225. package/dist/table-DjYcNOFm.d.cts +44 -0
  226. package/dist/table-DqfqMkVq.d.ts +44 -0
  227. package/dist/table-DvS_7UQS.d.ts +35 -0
  228. package/dist/{vector-ClohqsOe.d.cts → vector-Puuqu_IT.d.cts} +4 -0
  229. package/dist/{vector-ClohqsOe.d.ts → vector-Puuqu_IT.d.ts} +4 -0
  230. package/dist/write-DuyfnbL_.d.cts +16 -0
  231. package/dist/write-Zqwx6pka.d.ts +16 -0
  232. package/package.json +4 -4
  233. package/dist/odf/formula/placeholder.cjs +0 -36
  234. package/dist/odf/formula/placeholder.d.cts +0 -14
  235. package/dist/odf/formula/placeholder.d.ts +0 -14
  236. package/dist/odf/formula/placeholder.js +0 -36
@@ -7,6 +7,7 @@ import { buildOdtPackage } from "../edit/odt/content.js";
7
7
  import { buildOdpPackage } from "../edit/odp/content.js";
8
8
  import { buildOdsPackage } from "../edit/ods/content.js";
9
9
  import { buildOdgPackage } from "../edit/odg/content.js";
10
+ import { createDocumentFontRegistry, extractSourceFonts } from "../fonts/registry.js";
10
11
  import { layoutFormula } from "../mathml/layout.js";
11
12
  import { readDocxContent } from "../ooxml/docx/read.js";
12
13
  import { readPptxContent } from "../ooxml/pptx/read.js";
@@ -30,13 +31,17 @@ import { odbTablesToSpreadsheetDocument } from "../odb/spreadsheet.js";
30
31
  import { buildXlsxPackage, decodePackage, encodePackage, readXlsxContent } from "ooxml.js";
31
32
  import { COLOR_BLACK, CONTENT_FORMAT_VERSION, DOCUMENT_PACKAGE_FORMAT_VERSION, LAYOUT_FORMAT_VERSION } from "document-schema.js";
32
33
  import { decodePackage as decodePackage$1, encodePackage as encodePackage$1, readOdfMetadata, readOdfParagraph, readOdfTable, readOdm } from "odf.js";
33
- import { createStandardFontMeasurer, loadMathFont, readPdf, writePdf } from "pdf-codec";
34
+ import { createFontMeasurer, createFontRegistry, loadMathFont, readPdf, writePdf } from "pdf-codec";
34
35
  //#region src/convert/convert.ts
35
36
  function docxToPdf(bytes, options) {
36
37
  const pkg = openDocx(bytes).toPackage();
37
38
  const content = readDocxContent(pkg);
38
39
  if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
39
- const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createStandardFontMeasurer() });
40
+ const fonts = createDocumentFontRegistry({
41
+ kind: "docx",
42
+ package: pkg
43
+ }, options);
44
+ const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createFontMeasurer(fonts) });
40
45
  options?.onDocument?.({
41
46
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
42
47
  content,
@@ -45,33 +50,40 @@ function docxToPdf(bytes, options) {
45
50
  return writePdf(layout, {
46
51
  signal: options?.signal,
47
52
  onSubstitution: options?.onSubstitution,
48
- formulas
53
+ formulas,
54
+ fonts
49
55
  });
50
56
  }
51
57
  function odtToPdf(bytes, options) {
52
58
  const pkg = decodePackage$1(bytes);
53
59
  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
- });
60
+ if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
61
+ const fonts = createDocumentFontRegistry({
62
+ kind: "odf",
63
+ package: pkg
64
+ }, options);
65
+ const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createFontMeasurer(fonts) });
59
66
  options?.onDocument?.({
60
67
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
61
- content: content.document,
68
+ content,
62
69
  layout
63
70
  });
64
71
  return writePdf(layout, {
65
72
  signal: options?.signal,
66
73
  onSubstitution: options?.onSubstitution,
67
- formulas
74
+ formulas,
75
+ fonts
68
76
  });
69
77
  }
70
78
  function pptxToPdf(bytes, options) {
71
79
  const pkg = openPptx(bytes).toPackage();
72
80
  const content = readPptxContent(pkg);
73
81
  if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
74
- const { document: layout } = convertPresentationToLayout(content, { measurer: createStandardFontMeasurer() });
82
+ const fonts = createDocumentFontRegistry({
83
+ kind: "pptx",
84
+ package: pkg
85
+ }, options);
86
+ const { document: layout, formulas } = convertPresentationToLayout(content, { measurer: createFontMeasurer(fonts) });
75
87
  options?.onDocument?.({
76
88
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
77
89
  content,
@@ -79,34 +91,42 @@ function pptxToPdf(bytes, options) {
79
91
  });
80
92
  return writePdf(layout, {
81
93
  signal: options?.signal,
82
- onSubstitution: options?.onSubstitution
94
+ onSubstitution: options?.onSubstitution,
95
+ formulas,
96
+ fonts
83
97
  });
84
98
  }
85
99
  function odpToPdf(bytes, options) {
86
100
  const pkg = decodePackage$1(bytes);
87
101
  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
- });
102
+ if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
103
+ const fonts = createDocumentFontRegistry({
104
+ kind: "odf",
105
+ package: pkg
106
+ }, options);
107
+ const { document: layout, formulas } = convertPresentationToLayout(content, { measurer: createFontMeasurer(fonts) });
93
108
  options?.onDocument?.({
94
109
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
95
- content: content.document,
110
+ content,
96
111
  layout
97
112
  });
98
113
  return writePdf(layout, {
99
114
  signal: options?.signal,
100
115
  onSubstitution: options?.onSubstitution,
101
- formulas
116
+ formulas,
117
+ fonts
102
118
  });
103
119
  }
104
120
  function odsToPdf(bytes, options) {
105
121
  const pkg = decodePackage$1(bytes);
106
122
  const content = readOdsContent(pkg);
107
123
  if (content.kind !== "spreadsheet") throw new Error("readOdsContent returned a non-spreadsheet ContentDocument");
124
+ const fonts = createDocumentFontRegistry({
125
+ kind: "odf",
126
+ package: pkg
127
+ }, options);
108
128
  const layout = convertSpreadsheetToLayout(content, {
109
- measurer: createStandardFontMeasurer(),
129
+ measurer: createFontMeasurer(fonts),
110
130
  signal: options?.signal
111
131
  });
112
132
  options?.onDocument?.({
@@ -116,14 +136,19 @@ function odsToPdf(bytes, options) {
116
136
  });
117
137
  return writePdf(layout, {
118
138
  signal: options?.signal,
119
- onSubstitution: options?.onSubstitution
139
+ onSubstitution: options?.onSubstitution,
140
+ fonts
120
141
  });
121
142
  }
122
143
  function odgToPdf(bytes, options) {
123
144
  const pkg = decodePackage$1(bytes);
124
145
  const content = readOdgContent(pkg);
125
146
  if (content.kind !== "drawing") throw new Error("readOdgContent returned a non-drawing ContentDocument");
126
- const layout = convertDrawingToLayout(content, { measurer: createStandardFontMeasurer() });
147
+ const fonts = createDocumentFontRegistry({
148
+ kind: "odf",
149
+ package: pkg
150
+ }, options);
151
+ const layout = convertDrawingToLayout(content, { measurer: createFontMeasurer(fonts) });
127
152
  options?.onDocument?.({
128
153
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
129
154
  content,
@@ -131,7 +156,8 @@ function odgToPdf(bytes, options) {
131
156
  });
132
157
  return writePdf(layout, {
133
158
  signal: options?.signal,
134
- onSubstitution: options?.onSubstitution
159
+ onSubstitution: options?.onSubstitution,
160
+ fonts
135
161
  });
136
162
  }
137
163
  function markdownToPdf(bytes, options) {
@@ -139,7 +165,11 @@ function markdownToPdf(bytes, options) {
139
165
  const text = decodeMarkdownText(bytes);
140
166
  const content = readMarkdownContent(text, { signal: options?.signal });
141
167
  if (content.kind !== "wordprocessing") throw new Error("readMarkdownContent returned a non-wordprocessing ContentDocument");
142
- const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createStandardFontMeasurer() });
168
+ const fonts = createFontRegistry({
169
+ fonts: options?.fonts,
170
+ onSubstitution: options?.onFontSubstitution
171
+ });
172
+ const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createFontMeasurer(fonts) });
143
173
  options?.onDocument?.({
144
174
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
145
175
  content,
@@ -148,7 +178,8 @@ function markdownToPdf(bytes, options) {
148
178
  return writePdf(layout, {
149
179
  signal: options?.signal,
150
180
  onSubstitution: options?.onSubstitution,
151
- formulas
181
+ formulas,
182
+ fonts
152
183
  });
153
184
  }
154
185
  const STANDALONE_FORMULA_SIZE_PT = 18;
@@ -156,9 +187,10 @@ const STANDALONE_FORMULA_MARGIN_PT = 72;
156
187
  function odfToPdf(bytes, options) {
157
188
  throwIfAborted(options?.signal);
158
189
  const pkg = decodePackage$1(bytes);
159
- const formula = readOdfFormulaContent(pkg);
190
+ const content = readOdfFormulaContent(pkg);
191
+ if (content.kind !== "formula") throw new Error("readOdfFormulaContent returned a non-formula ContentDocument");
160
192
  const metrics = loadMathFont().metricsAt(STANDALONE_FORMULA_SIZE_PT);
161
- const { box } = layoutFormula(formula.mathml, {
193
+ const { box } = layoutFormula(content.formula.mathml, {
162
194
  metrics,
163
195
  sizePt: STANDALONE_FORMULA_SIZE_PT,
164
196
  color: COLOR_BLACK
@@ -171,7 +203,7 @@ function odfToPdf(bytes, options) {
171
203
  }, PAGE_SIZE_A4.heightPt);
172
204
  const layout = {
173
205
  formatVersion: LAYOUT_FORMAT_VERSION,
174
- metadata: formula.metadata,
206
+ metadata: content.metadata,
175
207
  pages: [{
176
208
  widthPt: PAGE_SIZE_A4.widthPt,
177
209
  heightPt: PAGE_SIZE_A4.heightPt,
@@ -179,6 +211,11 @@ function odfToPdf(bytes, options) {
179
211
  }],
180
212
  images: {}
181
213
  };
214
+ options?.onDocument?.({
215
+ formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
216
+ content,
217
+ layout
218
+ });
182
219
  throwIfAborted(options?.signal);
183
220
  return writePdf(layout, {
184
221
  signal: options?.signal,
@@ -285,14 +322,14 @@ function pdfToMarkdown(bytes, options) {
285
322
  function odtToDocx(bytes, options) {
286
323
  throwIfAborted(options?.signal);
287
324
  const pkg = decodePackage$1(bytes);
288
- const content = readOdtContent(pkg).document;
325
+ const content = readOdtContent(pkg);
289
326
  if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
290
327
  throwIfAborted(options?.signal);
291
328
  options?.onDocument?.({
292
329
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
293
330
  content
294
331
  });
295
- return encodePackage(buildDocxPackage(content));
332
+ return encodePackage(buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
296
333
  }
297
334
  function docxToOdt(bytes, options) {
298
335
  throwIfAborted(options?.signal);
@@ -309,7 +346,7 @@ function docxToOdt(bytes, options) {
309
346
  function odpToPptx(bytes, options) {
310
347
  throwIfAborted(options?.signal);
311
348
  const pkg = decodePackage$1(bytes);
312
- const content = readOdpContent(pkg).document;
349
+ const content = readOdpContent(pkg);
313
350
  if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
314
351
  throwIfAborted(options?.signal);
315
352
  options?.onDocument?.({
@@ -364,7 +401,7 @@ function markdownToDocx(bytes, options) {
364
401
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
365
402
  content
366
403
  });
367
- return encodePackage(buildDocxPackage(content));
404
+ return encodePackage(buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
368
405
  }
369
406
  function docxToMarkdown(bytes, options) {
370
407
  throwIfAborted(options?.signal);
@@ -394,7 +431,7 @@ function markdownToOdt(bytes, options) {
394
431
  function odtToMarkdown(bytes, options) {
395
432
  throwIfAborted(options?.signal);
396
433
  const pkg = decodePackage$1(bytes);
397
- const content = readOdtContent(pkg).document;
434
+ const content = readOdtContent(pkg);
398
435
  if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
399
436
  throwIfAborted(options?.signal);
400
437
  options?.onDocument?.({
@@ -411,7 +448,9 @@ function xlsxToPdf(bytes, options) {
411
448
  return odsToPdf(odsBytes, {
412
449
  signal: options?.signal,
413
450
  onSubstitution: options?.onSubstitution,
414
- onDocument: options?.onDocument
451
+ onDocument: options?.onDocument,
452
+ fonts: options?.fonts,
453
+ onFontSubstitution: options?.onFontSubstitution
415
454
  });
416
455
  }
417
456
  function pdfToXlsx(bytes, options) {
@@ -467,6 +506,10 @@ function odmToPdf(bytes, options) {
467
506
  const odm = readOdm(pkg);
468
507
  const unresolvedHrefs = [];
469
508
  const chapterSections = [];
509
+ const sourceFonts = extractSourceFonts({
510
+ kind: "odf",
511
+ package: pkg
512
+ });
470
513
  for (const section of odm.sections) {
471
514
  throwIfAborted(options?.signal);
472
515
  if (section.inlineContent !== void 0) {
@@ -479,7 +522,11 @@ function odmToPdf(bytes, options) {
479
522
  continue;
480
523
  }
481
524
  const chapterPkg = decodePackage$1(chapterBytes);
482
- const chapterContent = readOdtContent(chapterPkg).document;
525
+ sourceFonts.push(...extractSourceFonts({
526
+ kind: "odf",
527
+ package: chapterPkg
528
+ }));
529
+ const chapterContent = readOdtContent(chapterPkg);
483
530
  if (chapterContent.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
484
531
  chapterSections.push(chapterContent.sections);
485
532
  }
@@ -499,16 +546,23 @@ function odmToPdf(bytes, options) {
499
546
  metadata: readOdfMetadata(pkg),
500
547
  sections: combinedSections
501
548
  };
502
- const { document: layout } = convertWordprocessingToLayout(content, { measurer: createStandardFontMeasurer() });
549
+ const fonts = createFontRegistry({
550
+ sourceFonts,
551
+ fonts: options?.fonts,
552
+ onSubstitution: options?.onFontSubstitution
553
+ });
554
+ const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createFontMeasurer(fonts) });
503
555
  return writePdf(layout, {
504
556
  signal: options?.signal,
505
- onSubstitution: options?.onSubstitution
557
+ onSubstitution: options?.onSubstitution,
558
+ formulas,
559
+ fonts
506
560
  });
507
561
  }
508
562
  function odbToXlsx(bytes, options) {
509
563
  throwIfAborted(options?.signal);
510
564
  const pkg = decodePackage$1(bytes);
511
- const tables = readOdbTables(pkg);
565
+ const tables = readOdbTables(pkg, { timeZone: options?.timeZone });
512
566
  throwIfAborted(options?.signal);
513
567
  const content = odbTablesToSpreadsheetDocument(tables);
514
568
  return encodePackage(buildXlsxPackage(content));
@@ -516,7 +570,7 @@ function odbToXlsx(bytes, options) {
516
570
  function odbToCsv(bytes, options) {
517
571
  throwIfAborted(options?.signal);
518
572
  const pkg = decodePackage$1(bytes);
519
- const tables = readOdbTables(pkg);
573
+ const tables = readOdbTables(pkg, { timeZone: options?.timeZone });
520
574
  throwIfAborted(options?.signal);
521
575
  return buildOdbTableCsv(tables, options?.table);
522
576
  }
@@ -13,6 +13,13 @@ function substitutionDiagnostic(substitution, context) {
13
13
  pageIndex: context.pageIndex
14
14
  };
15
15
  }
16
+ function fontSubstitutionDiagnostic(substitution) {
17
+ return {
18
+ severity: "info",
19
+ code: "font/substituted",
20
+ message: `"${`${substitution.requestedFamily}${substitution.requestedBold ? " bold" : ""}${substitution.requestedItalic ? " italic" : ""}`}" is not available; ${substitution.reason === "vendored-substitute" ? `substituted the metric-compatible "${substitution.resolvedFamily}"` : `substituted another face of "${substitution.resolvedFamily}"`}`
21
+ };
22
+ }
16
23
  function fromPdfDiagnostic(diagnostic) {
17
24
  return {
18
25
  severity: diagnostic.severity,
@@ -23,7 +30,7 @@ function fromPdfDiagnostic(diagnostic) {
23
30
  }
24
31
  function createLocalDocumentConverter() {
25
32
  return {
26
- contractVersion: 2,
33
+ contractVersion: 3,
27
34
  conversions: SUPPORTED_CONVERSIONS,
28
35
  convert(request, options) {
29
36
  const { source, targetFormat } = request;
@@ -32,6 +39,10 @@ function createLocalDocumentConverter() {
32
39
  const onDocument = (pkg) => {
33
40
  documentPackage = pkg;
34
41
  };
42
+ const onFontSubstitution = (substitution) => {
43
+ diagnostics.push(fontSubstitutionDiagnostic(substitution));
44
+ options.onFontSubstitution?.(substitution);
45
+ };
35
46
  const strategy = require_convert_capability.resolveConversionPath(source.format, targetFormat);
36
47
  if (strategy?.kind !== "direct") return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
37
48
  const edge = strategy.edge;
@@ -39,7 +50,9 @@ function createLocalDocumentConverter() {
39
50
  const bytes = edge.convert(source.bytes, {
40
51
  signal: options.signal,
41
52
  onSubstitution: (s, c) => diagnostics.push(substitutionDiagnostic(s, c)),
42
- onDocument
53
+ onDocument,
54
+ fonts: options.fonts,
55
+ onFontSubstitution
43
56
  });
44
57
  return Promise.resolve({
45
58
  document: {
@@ -12,6 +12,13 @@ function substitutionDiagnostic(substitution, context) {
12
12
  pageIndex: context.pageIndex
13
13
  };
14
14
  }
15
+ function fontSubstitutionDiagnostic(substitution) {
16
+ return {
17
+ severity: "info",
18
+ code: "font/substituted",
19
+ message: `"${`${substitution.requestedFamily}${substitution.requestedBold ? " bold" : ""}${substitution.requestedItalic ? " italic" : ""}`}" is not available; ${substitution.reason === "vendored-substitute" ? `substituted the metric-compatible "${substitution.resolvedFamily}"` : `substituted another face of "${substitution.resolvedFamily}"`}`
20
+ };
21
+ }
15
22
  function fromPdfDiagnostic(diagnostic) {
16
23
  return {
17
24
  severity: diagnostic.severity,
@@ -22,7 +29,7 @@ function fromPdfDiagnostic(diagnostic) {
22
29
  }
23
30
  function createLocalDocumentConverter() {
24
31
  return {
25
- contractVersion: 2,
32
+ contractVersion: 3,
26
33
  conversions: SUPPORTED_CONVERSIONS,
27
34
  convert(request, options) {
28
35
  const { source, targetFormat } = request;
@@ -31,6 +38,10 @@ function createLocalDocumentConverter() {
31
38
  const onDocument = (pkg) => {
32
39
  documentPackage = pkg;
33
40
  };
41
+ const onFontSubstitution = (substitution) => {
42
+ diagnostics.push(fontSubstitutionDiagnostic(substitution));
43
+ options.onFontSubstitution?.(substitution);
44
+ };
34
45
  const strategy = resolveConversionPath(source.format, targetFormat);
35
46
  if (strategy?.kind !== "direct") return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
36
47
  const edge = strategy.edge;
@@ -38,7 +49,9 @@ function createLocalDocumentConverter() {
38
49
  const bytes = edge.convert(source.bytes, {
39
50
  signal: options.signal,
40
51
  onSubstitution: (s, c) => diagnostics.push(substitutionDiagnostic(s, c)),
41
- onDocument
52
+ onDocument,
53
+ fonts: options.fonts,
54
+ onFontSubstitution
42
55
  });
43
56
  return Promise.resolve({
44
57
  document: {
@@ -1,4 +1,5 @@
1
1
  import { DocumentPackage } from "document-schema.js";
2
+ import { FontSubstitution, ProvidedFont } from "pdf-codec";
2
3
  //#region src/convert/port.d.ts
3
4
  type DocumentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'odf' | 'markdown' | 'pdf';
4
5
  interface DocumentPayload {
@@ -20,15 +21,18 @@ interface ConversionResult {
20
21
  readonly diagnostics: readonly Diagnostic[];
21
22
  readonly package?: DocumentPackage;
22
23
  }
24
+ interface ConversionOptions {
25
+ readonly signal: AbortSignal;
26
+ readonly fonts?: readonly ProvidedFont[];
27
+ readonly onFontSubstitution?: (substitution: FontSubstitution) => void;
28
+ }
23
29
  interface DocumentConverter {
24
30
  readonly contractVersion: number;
25
31
  readonly conversions: readonly {
26
32
  readonly source: DocumentFormat;
27
33
  readonly target: DocumentFormat;
28
34
  }[];
29
- convert(request: ConversionRequest, options: {
30
- readonly signal: AbortSignal;
31
- }): Promise<ConversionResult>;
35
+ convert(request: ConversionRequest, options: ConversionOptions): Promise<ConversionResult>;
32
36
  }
33
37
  //#endregion
34
- export { ConversionRequest, ConversionResult, Diagnostic, DocumentConverter, DocumentFormat, DocumentPayload };
38
+ export { ConversionOptions, ConversionRequest, ConversionResult, Diagnostic, DocumentConverter, DocumentFormat, DocumentPayload };
@@ -1,4 +1,5 @@
1
1
  import { DocumentPackage } from "document-schema.js";
2
+ import { FontSubstitution, ProvidedFont } from "pdf-codec";
2
3
  //#region src/convert/port.d.ts
3
4
  type DocumentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'odf' | 'markdown' | 'pdf';
4
5
  interface DocumentPayload {
@@ -20,15 +21,18 @@ interface ConversionResult {
20
21
  readonly diagnostics: readonly Diagnostic[];
21
22
  readonly package?: DocumentPackage;
22
23
  }
24
+ interface ConversionOptions {
25
+ readonly signal: AbortSignal;
26
+ readonly fonts?: readonly ProvidedFont[];
27
+ readonly onFontSubstitution?: (substitution: FontSubstitution) => void;
28
+ }
23
29
  interface DocumentConverter {
24
30
  readonly contractVersion: number;
25
31
  readonly conversions: readonly {
26
32
  readonly source: DocumentFormat;
27
33
  readonly target: DocumentFormat;
28
34
  }[];
29
- convert(request: ConversionRequest, options: {
30
- readonly signal: AbortSignal;
31
- }): Promise<ConversionResult>;
35
+ convert(request: ConversionRequest, options: ConversionOptions): Promise<ConversionResult>;
32
36
  }
33
37
  //#endregion
34
- export { ConversionRequest, ConversionResult, Diagnostic, DocumentConverter, DocumentFormat, DocumentPayload };
38
+ export { ConversionOptions, ConversionRequest, ConversionResult, Diagnostic, DocumentConverter, DocumentFormat, DocumentPayload };
@@ -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 };