documents.js 1.97.11 → 1.98.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.
- package/dist/capability-DX0lCSiI.d.ts +16 -0
- package/dist/capability-an5gSNsu.d.cts +16 -0
- package/dist/convert/capability.cjs +65 -5
- package/dist/convert/capability.d.cts +2 -38
- package/dist/convert/capability.d.ts +2 -38
- package/dist/convert/capability.js +64 -2
- package/dist/convert/codec.cjs +29 -29
- package/dist/convert/codec.js +1 -1
- package/dist/convert/composition.cjs +414 -4
- package/dist/convert/composition.d.cts +2 -2
- package/dist/convert/composition.d.ts +1 -1
- package/dist/convert/composition.js +411 -1
- package/dist/convert/convert.cjs +350 -42
- package/dist/convert/convert.d.cts +105 -1
- package/dist/convert/convert.d.ts +105 -1
- package/dist/convert/convert.js +309 -1
- package/dist/convert/local.cjs +23 -8
- package/dist/convert/local.js +20 -5
- package/dist/fonts/registry.d.cts +19 -1
- package/dist/fonts/registry.d.ts +19 -1
- package/dist/hsqldb/binary-script.d.cts +1 -1
- package/dist/hsqldb/binary-script.d.ts +1 -1
- package/dist/hsqldb/cache.d.cts +1 -1
- package/dist/hsqldb/cache.d.ts +1 -1
- package/dist/hsqldb/rowformat.d.cts +24 -1
- package/dist/hsqldb/rowformat.d.ts +24 -1
- package/dist/index.cjs +44 -41
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +6 -5
- package/dist/index.js +3 -2
- package/dist/metadata/read.cjs +2 -2
- package/dist/metadata/read.js +1 -1
- package/dist/odb/read.d.cts +1 -1
- package/dist/odb/read.d.ts +1 -1
- package/dist/odb/report/content.d.cts +1 -1
- package/dist/odb/report/content.d.ts +1 -1
- package/dist/odb/report/source.d.cts +1 -1
- package/dist/odb/report/source.d.ts +1 -1
- package/package.json +1 -1
- package/dist/convert-B1izrvnQ.d.cts +0 -106
- package/dist/convert-BO_4tCwz.cjs +0 -1262
- package/dist/convert-HYsWA-LI.d.ts +0 -106
- package/dist/convert-ULGgwmSb.js +0 -975
- package/dist/registry-DpF4A9EM.d.ts +0 -20
- package/dist/registry-ZAWlWHqJ.d.cts +0 -20
- package/dist/rowformat-Cl2exlEh.d.cts +0 -25
- package/dist/rowformat-Cl2exlEh.d.ts +0 -25
package/dist/convert-ULGgwmSb.js
DELETED
|
@@ -1,975 +0,0 @@
|
|
|
1
|
-
import { flipY } from "./model/geometry.js";
|
|
2
|
-
import { resolveMetadataTimestamps } from "./model/metadata.js";
|
|
3
|
-
import { buildDocxPackage } from "./edit/docx/content.js";
|
|
4
|
-
import { buildPptxPackage } from "./edit/pptx/content.js";
|
|
5
|
-
import { buildOdtPackage } from "./edit/odt/content.js";
|
|
6
|
-
import { buildOdpPackage } from "./edit/odp/content.js";
|
|
7
|
-
import { buildOdsPackage } from "./edit/ods/content.js";
|
|
8
|
-
import { buildOdgPackage } from "./edit/odg/content.js";
|
|
9
|
-
import { readMarkdownContent } from "./markdown/read.js";
|
|
10
|
-
import { buildMarkdownText } from "./markdown/write.js";
|
|
11
|
-
import { createDocumentFontRegistry, extractSourceFonts } from "./fonts/registry.js";
|
|
12
|
-
import { layoutFormula } from "./mathml/layout.js";
|
|
13
|
-
import { readDocxContent } from "./ooxml/docx/read.js";
|
|
14
|
-
import { readPptxContent } from "./ooxml/pptx/read.js";
|
|
15
|
-
import { readOdfFormulaContent } from "./odf/formula/read.js";
|
|
16
|
-
import { readOdtContent } from "./odf/odt/read.js";
|
|
17
|
-
import { readOdpContent } from "./odf/odp/read.js";
|
|
18
|
-
import { readOdsContent } from "./odf/ods/read.js";
|
|
19
|
-
import { readOdgContent } from "./odf/odg/read.js";
|
|
20
|
-
import { decodeMarkdownText, encodeMarkdownText } from "./markdown/text.js";
|
|
21
|
-
import { convertWordprocessingToLayout } from "./layout/engine.js";
|
|
22
|
-
import { convertPresentationToLayout } from "./layout/slides.js";
|
|
23
|
-
import { throwIfAborted } from "./ports/abort.js";
|
|
24
|
-
import { convertSpreadsheetToLayout } from "./layout/sheets.js";
|
|
25
|
-
import { convertDrawingToLayout } from "./layout/drawing.js";
|
|
26
|
-
import { reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing } from "./layout/reconstruct.js";
|
|
27
|
-
import { buildOdbTableCsv } from "./odb/csv.js";
|
|
28
|
-
import { readOdbTables } from "./odb/read.js";
|
|
29
|
-
import { odbTablesToSpreadsheetDocument } from "./odb/spreadsheet.js";
|
|
30
|
-
import { presentationToWordprocessing, wordprocessingToPresentation } from "./convert/variant-bridges.js";
|
|
31
|
-
import { buildXlsxPackage, decodePackage, encodePackage, readXlsxContent } from "ooxml.js";
|
|
32
|
-
import { COLOR_BLACK, CONTENT_FORMAT_VERSION, DOCUMENT_PACKAGE_FORMAT_VERSION, LAYOUT_FORMAT_VERSION, PAGE_SIZE_A4 } from "document-schema.js";
|
|
33
|
-
import { decodePackage as decodePackage$1, encodePackage as encodePackage$1, readOdfMetadata, readOdfParagraph, readOdfTable, readOdm } from "odf.js";
|
|
34
|
-
import "markdown-codec";
|
|
35
|
-
import { createFontMeasurer, createFontRegistry, loadMathFont, readPdf, writePdf } from "pdf-codec";
|
|
36
|
-
//#region src/convert/capability.ts
|
|
37
|
-
const FORMAT_CAPABILITIES = {
|
|
38
|
-
docx: {
|
|
39
|
-
format: "docx",
|
|
40
|
-
variant: "wordprocessing",
|
|
41
|
-
hasLayoutPath: true
|
|
42
|
-
},
|
|
43
|
-
odt: {
|
|
44
|
-
format: "odt",
|
|
45
|
-
variant: "wordprocessing",
|
|
46
|
-
hasLayoutPath: true
|
|
47
|
-
},
|
|
48
|
-
pptx: {
|
|
49
|
-
format: "pptx",
|
|
50
|
-
variant: "presentation",
|
|
51
|
-
hasLayoutPath: true
|
|
52
|
-
},
|
|
53
|
-
odp: {
|
|
54
|
-
format: "odp",
|
|
55
|
-
variant: "presentation",
|
|
56
|
-
hasLayoutPath: true
|
|
57
|
-
},
|
|
58
|
-
ods: {
|
|
59
|
-
format: "ods",
|
|
60
|
-
variant: "spreadsheet",
|
|
61
|
-
hasLayoutPath: true
|
|
62
|
-
},
|
|
63
|
-
xlsx: {
|
|
64
|
-
format: "xlsx",
|
|
65
|
-
variant: "spreadsheet",
|
|
66
|
-
hasLayoutPath: false
|
|
67
|
-
},
|
|
68
|
-
odg: {
|
|
69
|
-
format: "odg",
|
|
70
|
-
variant: "drawing",
|
|
71
|
-
hasLayoutPath: true
|
|
72
|
-
},
|
|
73
|
-
odf: {
|
|
74
|
-
format: "odf",
|
|
75
|
-
variant: "formula",
|
|
76
|
-
hasLayoutPath: false
|
|
77
|
-
},
|
|
78
|
-
markdown: {
|
|
79
|
-
format: "markdown",
|
|
80
|
-
variant: "wordprocessing",
|
|
81
|
-
hasLayoutPath: true
|
|
82
|
-
},
|
|
83
|
-
pdf: {
|
|
84
|
-
format: "pdf",
|
|
85
|
-
hasLayoutPath: false
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const DIRECT_EDGES = [
|
|
89
|
-
{
|
|
90
|
-
kind: "toPdf",
|
|
91
|
-
source: "docx",
|
|
92
|
-
target: "pdf",
|
|
93
|
-
convert: docxToPdf
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
kind: "toPdf",
|
|
97
|
-
source: "pptx",
|
|
98
|
-
target: "pdf",
|
|
99
|
-
convert: pptxToPdf
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
kind: "toPdf",
|
|
103
|
-
source: "odt",
|
|
104
|
-
target: "pdf",
|
|
105
|
-
convert: odtToPdf
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
kind: "toPdf",
|
|
109
|
-
source: "odp",
|
|
110
|
-
target: "pdf",
|
|
111
|
-
convert: odpToPdf
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
kind: "toPdf",
|
|
115
|
-
source: "ods",
|
|
116
|
-
target: "pdf",
|
|
117
|
-
convert: odsToPdf
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
kind: "toPdf",
|
|
121
|
-
source: "odg",
|
|
122
|
-
target: "pdf",
|
|
123
|
-
convert: odgToPdf
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
kind: "toPdf",
|
|
127
|
-
source: "odf",
|
|
128
|
-
target: "pdf",
|
|
129
|
-
convert: odfToPdf
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
kind: "toPdf",
|
|
133
|
-
source: "xlsx",
|
|
134
|
-
target: "pdf",
|
|
135
|
-
convert: xlsxToPdf
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
kind: "toPdf",
|
|
139
|
-
source: "markdown",
|
|
140
|
-
target: "pdf",
|
|
141
|
-
convert: markdownToPdf
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
kind: "fromPdf",
|
|
145
|
-
source: "pdf",
|
|
146
|
-
target: "docx",
|
|
147
|
-
convert: pdfToDocx
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
kind: "fromPdf",
|
|
151
|
-
source: "pdf",
|
|
152
|
-
target: "pptx",
|
|
153
|
-
convert: pdfToPptx
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
kind: "fromPdf",
|
|
157
|
-
source: "pdf",
|
|
158
|
-
target: "odt",
|
|
159
|
-
convert: pdfToOdt
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
kind: "fromPdf",
|
|
163
|
-
source: "pdf",
|
|
164
|
-
target: "odp",
|
|
165
|
-
convert: pdfToOdp
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
kind: "fromPdf",
|
|
169
|
-
source: "pdf",
|
|
170
|
-
target: "ods",
|
|
171
|
-
convert: pdfToOds
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
kind: "fromPdf",
|
|
175
|
-
source: "pdf",
|
|
176
|
-
target: "odg",
|
|
177
|
-
convert: pdfToOdg
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
kind: "fromPdf",
|
|
181
|
-
source: "pdf",
|
|
182
|
-
target: "xlsx",
|
|
183
|
-
convert: pdfToXlsx
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
kind: "fromPdf",
|
|
187
|
-
source: "pdf",
|
|
188
|
-
target: "markdown",
|
|
189
|
-
convert: pdfToMarkdown
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
kind: "bridge",
|
|
193
|
-
source: "odt",
|
|
194
|
-
target: "docx",
|
|
195
|
-
convert: odtToDocx
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
kind: "bridge",
|
|
199
|
-
source: "docx",
|
|
200
|
-
target: "odt",
|
|
201
|
-
convert: docxToOdt
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
kind: "bridge",
|
|
205
|
-
source: "odp",
|
|
206
|
-
target: "pptx",
|
|
207
|
-
convert: odpToPptx
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
kind: "bridge",
|
|
211
|
-
source: "pptx",
|
|
212
|
-
target: "odp",
|
|
213
|
-
convert: pptxToOdp
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
kind: "bridge",
|
|
217
|
-
source: "ods",
|
|
218
|
-
target: "xlsx",
|
|
219
|
-
convert: odsToXlsx
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
kind: "bridge",
|
|
223
|
-
source: "xlsx",
|
|
224
|
-
target: "ods",
|
|
225
|
-
convert: xlsxToOds
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
kind: "bridge",
|
|
229
|
-
source: "markdown",
|
|
230
|
-
target: "docx",
|
|
231
|
-
convert: markdownToDocx
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
kind: "bridge",
|
|
235
|
-
source: "docx",
|
|
236
|
-
target: "markdown",
|
|
237
|
-
convert: docxToMarkdown
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
kind: "bridge",
|
|
241
|
-
source: "markdown",
|
|
242
|
-
target: "odt",
|
|
243
|
-
convert: markdownToOdt
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
kind: "bridge",
|
|
247
|
-
source: "odt",
|
|
248
|
-
target: "markdown",
|
|
249
|
-
convert: odtToMarkdown
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
kind: "bridge",
|
|
253
|
-
source: "docx",
|
|
254
|
-
target: "pptx",
|
|
255
|
-
convert: docxToPptx
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
kind: "bridge",
|
|
259
|
-
source: "pptx",
|
|
260
|
-
target: "docx",
|
|
261
|
-
convert: pptxToDocx
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
kind: "bridge",
|
|
265
|
-
source: "odt",
|
|
266
|
-
target: "odp",
|
|
267
|
-
convert: odtToOdp
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
kind: "bridge",
|
|
271
|
-
source: "odp",
|
|
272
|
-
target: "odt",
|
|
273
|
-
convert: odpToOdt
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
kind: "bridge",
|
|
277
|
-
source: "xlsx",
|
|
278
|
-
target: "markdown",
|
|
279
|
-
convert: xlsxToMarkdown
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
kind: "bridge",
|
|
283
|
-
source: "markdown",
|
|
284
|
-
target: "xlsx",
|
|
285
|
-
convert: markdownToXlsx
|
|
286
|
-
}
|
|
287
|
-
];
|
|
288
|
-
var UnsupportedConversionError = class extends Error {
|
|
289
|
-
source;
|
|
290
|
-
target;
|
|
291
|
-
constructor(source, target) {
|
|
292
|
-
super(`unsupported conversion: ${source} -> ${target}`);
|
|
293
|
-
this.name = "UnsupportedConversionError";
|
|
294
|
-
this.source = source;
|
|
295
|
-
this.target = target;
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
function resolveConversionPath(source, target, edges = DIRECT_EDGES) {
|
|
299
|
-
if (source === target) return;
|
|
300
|
-
return edges.find((edge) => edge.source === source && edge.target === target);
|
|
301
|
-
}
|
|
302
|
-
//#endregion
|
|
303
|
-
//#region src/convert/composition.ts
|
|
304
|
-
const mathMetricsAt$1 = (sizePt) => loadMathFont().metricsAt(sizePt);
|
|
305
|
-
const CONTENT_FORMATS = [
|
|
306
|
-
"docx",
|
|
307
|
-
"pptx",
|
|
308
|
-
"xlsx",
|
|
309
|
-
"odt",
|
|
310
|
-
"odp",
|
|
311
|
-
"ods",
|
|
312
|
-
"odg",
|
|
313
|
-
"markdown"
|
|
314
|
-
];
|
|
315
|
-
const FORMAT_NODES = {
|
|
316
|
-
docx: {
|
|
317
|
-
variant: "wordprocessing",
|
|
318
|
-
family: "ooxml",
|
|
319
|
-
decode: (bytes) => decodePackage(bytes),
|
|
320
|
-
read: (pkg, options) => readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic }),
|
|
321
|
-
build: (content, options) => buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }),
|
|
322
|
-
encode: (pkg) => encodePackage(pkg),
|
|
323
|
-
hasSourcePackage: true
|
|
324
|
-
},
|
|
325
|
-
pptx: {
|
|
326
|
-
variant: "presentation",
|
|
327
|
-
family: "ooxml",
|
|
328
|
-
decode: (bytes) => decodePackage(bytes),
|
|
329
|
-
read: (pkg) => readPptxContent(pkg),
|
|
330
|
-
build: (content) => buildPptxPackage(content),
|
|
331
|
-
encode: (pkg) => encodePackage(pkg),
|
|
332
|
-
hasSourcePackage: true
|
|
333
|
-
},
|
|
334
|
-
xlsx: {
|
|
335
|
-
variant: "spreadsheet",
|
|
336
|
-
family: "ooxml",
|
|
337
|
-
decode: (bytes) => decodePackage(bytes),
|
|
338
|
-
read: (pkg) => readXlsxContent(pkg),
|
|
339
|
-
build: (content) => buildXlsxPackage(content),
|
|
340
|
-
encode: (pkg) => encodePackage(pkg),
|
|
341
|
-
hasSourcePackage: true
|
|
342
|
-
},
|
|
343
|
-
odt: {
|
|
344
|
-
variant: "wordprocessing",
|
|
345
|
-
family: "odf",
|
|
346
|
-
decode: (bytes) => decodePackage$1(bytes),
|
|
347
|
-
read: (pkg) => readOdtContent(pkg),
|
|
348
|
-
build: (content) => buildOdtPackage(content),
|
|
349
|
-
encode: (pkg) => encodePackage$1(pkg),
|
|
350
|
-
hasSourcePackage: true
|
|
351
|
-
},
|
|
352
|
-
odp: {
|
|
353
|
-
variant: "presentation",
|
|
354
|
-
family: "odf",
|
|
355
|
-
decode: (bytes) => decodePackage$1(bytes),
|
|
356
|
-
read: (pkg) => readOdpContent(pkg),
|
|
357
|
-
build: (content) => buildOdpPackage(content),
|
|
358
|
-
encode: (pkg) => encodePackage$1(pkg),
|
|
359
|
-
hasSourcePackage: true
|
|
360
|
-
},
|
|
361
|
-
ods: {
|
|
362
|
-
variant: "spreadsheet",
|
|
363
|
-
family: "odf",
|
|
364
|
-
decode: (bytes) => decodePackage$1(bytes),
|
|
365
|
-
read: (pkg) => readOdsContent(pkg),
|
|
366
|
-
build: (content) => buildOdsPackage(content),
|
|
367
|
-
encode: (pkg) => encodePackage$1(pkg),
|
|
368
|
-
hasSourcePackage: true
|
|
369
|
-
},
|
|
370
|
-
odg: {
|
|
371
|
-
variant: "drawing",
|
|
372
|
-
family: "odf",
|
|
373
|
-
decode: (bytes) => decodePackage$1(bytes),
|
|
374
|
-
read: (pkg) => readOdgContent(pkg),
|
|
375
|
-
build: (content) => buildOdgPackage(content),
|
|
376
|
-
encode: (pkg) => encodePackage$1(pkg),
|
|
377
|
-
hasSourcePackage: true
|
|
378
|
-
},
|
|
379
|
-
markdown: {
|
|
380
|
-
variant: "wordprocessing",
|
|
381
|
-
family: "markdown",
|
|
382
|
-
decode: (bytes) => decodeMarkdownText(bytes),
|
|
383
|
-
read: (text, options) => readMarkdownContent(text, {
|
|
384
|
-
signal: options?.signal,
|
|
385
|
-
images: options?.images
|
|
386
|
-
}),
|
|
387
|
-
build: (content) => buildMarkdownText(content),
|
|
388
|
-
encode: (text) => encodeMarkdownText(text),
|
|
389
|
-
hasSourcePackage: false
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
const LAYOUT_CAPABLE = /* @__PURE__ */ new Set([
|
|
393
|
-
"docx",
|
|
394
|
-
"pptx",
|
|
395
|
-
"odt",
|
|
396
|
-
"odp",
|
|
397
|
-
"ods",
|
|
398
|
-
"odg",
|
|
399
|
-
"markdown"
|
|
400
|
-
]);
|
|
401
|
-
const TRANSFORMS = {
|
|
402
|
-
"wordprocessing->presentation": (doc) => {
|
|
403
|
-
if (doc.kind !== "wordprocessing") throw new Error("wordprocessingToPresentation: expected a wordprocessing ContentDocument");
|
|
404
|
-
return wordprocessingToPresentation(doc);
|
|
405
|
-
},
|
|
406
|
-
"presentation->wordprocessing": (doc) => {
|
|
407
|
-
if (doc.kind !== "presentation") throw new Error("presentationToWordprocessing: expected a presentation ContentDocument");
|
|
408
|
-
return presentationToWordprocessing(doc);
|
|
409
|
-
}
|
|
410
|
-
};
|
|
411
|
-
const LAYOUT_ENGINES = {
|
|
412
|
-
wordprocessing: convertWordprocessingToLayout,
|
|
413
|
-
presentation: convertPresentationToLayout,
|
|
414
|
-
spreadsheet: convertSpreadsheetToLayout,
|
|
415
|
-
drawing: convertDrawingToLayout
|
|
416
|
-
};
|
|
417
|
-
const RECONSTRUCTORS = {
|
|
418
|
-
wordprocessing: reconstructWordprocessing,
|
|
419
|
-
presentation: reconstructPresentation,
|
|
420
|
-
drawing: reconstructDrawing,
|
|
421
|
-
spreadsheet: reconstructSpreadsheet
|
|
422
|
-
};
|
|
423
|
-
function executeBridge(source, target, bytes, options) {
|
|
424
|
-
throwIfAborted(options?.signal);
|
|
425
|
-
const sourceNode = FORMAT_NODES[source];
|
|
426
|
-
const targetNode = FORMAT_NODES[target];
|
|
427
|
-
let content;
|
|
428
|
-
if (sourceNode.family === "markdown") {
|
|
429
|
-
const text = sourceNode.decode(bytes);
|
|
430
|
-
content = sourceNode.read(text, options);
|
|
431
|
-
} else {
|
|
432
|
-
const pkg = sourceNode.decode(bytes);
|
|
433
|
-
content = sourceNode.read(pkg, options);
|
|
434
|
-
}
|
|
435
|
-
if (content.kind !== sourceNode.variant) throw new Error(`executeBridge: ${source} read returned a non-${sourceNode.variant} ContentDocument`);
|
|
436
|
-
let buildContent = content;
|
|
437
|
-
if (sourceNode.variant !== targetNode.variant) {
|
|
438
|
-
const key = `${sourceNode.variant}->${targetNode.variant}`;
|
|
439
|
-
const transform = TRANSFORMS[key];
|
|
440
|
-
if (transform === void 0) throw new Error(`executeBridge: no transform registered for ${key}`);
|
|
441
|
-
buildContent = transform(content);
|
|
442
|
-
}
|
|
443
|
-
throwIfAborted(options?.signal);
|
|
444
|
-
options?.onDocument?.({
|
|
445
|
-
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
446
|
-
content: buildContent
|
|
447
|
-
});
|
|
448
|
-
if (targetNode.family === "markdown") {
|
|
449
|
-
const text = targetNode.build(buildContent);
|
|
450
|
-
return targetNode.encode(text);
|
|
451
|
-
}
|
|
452
|
-
const pkg = targetNode.build(buildContent, options);
|
|
453
|
-
return targetNode.encode(pkg);
|
|
454
|
-
}
|
|
455
|
-
function executeToPdf(format, bytes, options) {
|
|
456
|
-
if (!LAYOUT_CAPABLE.has(format)) throw new Error(`executeToPdf: '${format}' has no layout engine of its own`);
|
|
457
|
-
const node = FORMAT_NODES[format];
|
|
458
|
-
let content;
|
|
459
|
-
let fonts;
|
|
460
|
-
if (node.family === "markdown") {
|
|
461
|
-
throwIfAborted(options?.signal);
|
|
462
|
-
const text = node.decode(bytes);
|
|
463
|
-
const read = node.read(text, options);
|
|
464
|
-
content = {
|
|
465
|
-
...read,
|
|
466
|
-
metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
|
|
467
|
-
};
|
|
468
|
-
fonts = createFontRegistry({
|
|
469
|
-
fonts: options?.fonts,
|
|
470
|
-
onSubstitution: options?.onFontSubstitution
|
|
471
|
-
});
|
|
472
|
-
} else {
|
|
473
|
-
const pkg = node.decode(bytes);
|
|
474
|
-
const read = node.read(pkg, options);
|
|
475
|
-
content = {
|
|
476
|
-
...read,
|
|
477
|
-
metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
|
|
478
|
-
};
|
|
479
|
-
const fontSource = node.family === "odf" ? {
|
|
480
|
-
kind: "odf",
|
|
481
|
-
package: pkg
|
|
482
|
-
} : format === "pptx" ? {
|
|
483
|
-
kind: "pptx",
|
|
484
|
-
package: pkg
|
|
485
|
-
} : {
|
|
486
|
-
kind: "docx",
|
|
487
|
-
package: pkg
|
|
488
|
-
};
|
|
489
|
-
fonts = createDocumentFontRegistry(fontSource, {
|
|
490
|
-
fonts: options?.fonts,
|
|
491
|
-
onFontSubstitution: options?.onFontSubstitution
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
const measurer = createFontMeasurer(fonts);
|
|
495
|
-
let layout;
|
|
496
|
-
let formulas;
|
|
497
|
-
switch (content.kind) {
|
|
498
|
-
case "wordprocessing": {
|
|
499
|
-
const result = LAYOUT_ENGINES.wordprocessing(content, {
|
|
500
|
-
measurer,
|
|
501
|
-
mathMetricsAt: mathMetricsAt$1
|
|
502
|
-
});
|
|
503
|
-
layout = result.document;
|
|
504
|
-
formulas = result.formulas;
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
case "presentation": {
|
|
508
|
-
const result = LAYOUT_ENGINES.presentation(content, {
|
|
509
|
-
measurer,
|
|
510
|
-
mathMetricsAt: mathMetricsAt$1
|
|
511
|
-
});
|
|
512
|
-
layout = result.document;
|
|
513
|
-
formulas = result.formulas;
|
|
514
|
-
break;
|
|
515
|
-
}
|
|
516
|
-
case "spreadsheet": {
|
|
517
|
-
const result = LAYOUT_ENGINES.spreadsheet(content, {
|
|
518
|
-
measurer,
|
|
519
|
-
mathMetricsAt: mathMetricsAt$1,
|
|
520
|
-
signal: options?.signal
|
|
521
|
-
});
|
|
522
|
-
layout = result.document;
|
|
523
|
-
formulas = result.formulas;
|
|
524
|
-
break;
|
|
525
|
-
}
|
|
526
|
-
case "drawing":
|
|
527
|
-
layout = LAYOUT_ENGINES.drawing(content, { measurer });
|
|
528
|
-
break;
|
|
529
|
-
default: throw new Error(`executeToPdf: cannot lay out a '${content.kind}' document`);
|
|
530
|
-
}
|
|
531
|
-
options?.onDocument?.({
|
|
532
|
-
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
533
|
-
content,
|
|
534
|
-
layout
|
|
535
|
-
});
|
|
536
|
-
if (formulas === void 0) return writePdf(layout, {
|
|
537
|
-
signal: options?.signal,
|
|
538
|
-
onSubstitution: options?.onSubstitution,
|
|
539
|
-
fonts
|
|
540
|
-
});
|
|
541
|
-
return writePdf(layout, {
|
|
542
|
-
signal: options?.signal,
|
|
543
|
-
onSubstitution: options?.onSubstitution,
|
|
544
|
-
formulas,
|
|
545
|
-
fonts
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
function executeFromPdf(target, bytes, options) {
|
|
549
|
-
const node = FORMAT_NODES[target];
|
|
550
|
-
const layout = readPdf(bytes, {
|
|
551
|
-
signal: options?.signal,
|
|
552
|
-
sink: options?.sink
|
|
553
|
-
});
|
|
554
|
-
const content = RECONSTRUCTORS[node.variant](layout, { signal: options?.signal });
|
|
555
|
-
options?.onDocument?.({
|
|
556
|
-
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
557
|
-
content,
|
|
558
|
-
layout
|
|
559
|
-
});
|
|
560
|
-
if (node.family === "markdown") {
|
|
561
|
-
const text = node.build(content);
|
|
562
|
-
return node.encode(text);
|
|
563
|
-
}
|
|
564
|
-
const pkg = node.build(content);
|
|
565
|
-
return node.encode(pkg);
|
|
566
|
-
}
|
|
567
|
-
function buildCompositionGraph() {
|
|
568
|
-
const adj = /* @__PURE__ */ new Map();
|
|
569
|
-
const addDirected = (from, to, cost) => {
|
|
570
|
-
const list = adj.get(from);
|
|
571
|
-
if (list === void 0) adj.set(from, [{
|
|
572
|
-
to,
|
|
573
|
-
cost
|
|
574
|
-
}]);
|
|
575
|
-
else list.push({
|
|
576
|
-
to,
|
|
577
|
-
cost
|
|
578
|
-
});
|
|
579
|
-
};
|
|
580
|
-
const addEdge = (from, to, cost) => {
|
|
581
|
-
addDirected(from, to, cost);
|
|
582
|
-
addDirected(to, from, cost);
|
|
583
|
-
};
|
|
584
|
-
for (const a of CONTENT_FORMATS) for (const b of CONTENT_FORMATS) {
|
|
585
|
-
if (a === b) continue;
|
|
586
|
-
if (FORMAT_NODES[a].variant === FORMAT_NODES[b].variant) addEdge(a, b, 1);
|
|
587
|
-
}
|
|
588
|
-
for (const key of Object.keys(TRANSFORMS)) {
|
|
589
|
-
const parts = key.split("->");
|
|
590
|
-
const fromVariant = parts[0];
|
|
591
|
-
const toVariant = parts[1];
|
|
592
|
-
if (fromVariant === void 0 || toVariant === void 0) continue;
|
|
593
|
-
for (const a of CONTENT_FORMATS) {
|
|
594
|
-
if (FORMAT_NODES[a].variant !== fromVariant) continue;
|
|
595
|
-
for (const b of CONTENT_FORMATS) {
|
|
596
|
-
if (FORMAT_NODES[b].variant !== toVariant) continue;
|
|
597
|
-
addEdge(a, b, 2);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
for (const format of CONTENT_FORMATS) if (LAYOUT_CAPABLE.has(format)) addEdge(format, "pdf", 3);
|
|
602
|
-
return adj;
|
|
603
|
-
}
|
|
604
|
-
const COMPOSITION_GRAPH = buildCompositionGraph();
|
|
605
|
-
function shortestPath(source, target) {
|
|
606
|
-
if (source === target) return;
|
|
607
|
-
const distances = /* @__PURE__ */ new Map([[source, 0]]);
|
|
608
|
-
const previous = /* @__PURE__ */ new Map();
|
|
609
|
-
const visited = /* @__PURE__ */ new Set();
|
|
610
|
-
while (true) {
|
|
611
|
-
let current = void 0;
|
|
612
|
-
let currentDist = Infinity;
|
|
613
|
-
for (const [node, dist] of distances) if (!visited.has(node) && dist < currentDist) {
|
|
614
|
-
current = node;
|
|
615
|
-
currentDist = dist;
|
|
616
|
-
}
|
|
617
|
-
if (current === void 0 || current === target) break;
|
|
618
|
-
visited.add(current);
|
|
619
|
-
for (const edge of COMPOSITION_GRAPH.get(current) ?? []) {
|
|
620
|
-
if (visited.has(edge.to)) continue;
|
|
621
|
-
const alt = currentDist + edge.cost;
|
|
622
|
-
const known = distances.get(edge.to);
|
|
623
|
-
if (known === void 0 || alt < known) {
|
|
624
|
-
distances.set(edge.to, alt);
|
|
625
|
-
previous.set(edge.to, current);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
if (distances.get(target) === void 0) return;
|
|
630
|
-
const path = [];
|
|
631
|
-
let cursor = target;
|
|
632
|
-
while (cursor !== void 0) {
|
|
633
|
-
path.unshift(cursor);
|
|
634
|
-
cursor = previous.get(cursor);
|
|
635
|
-
}
|
|
636
|
-
return path;
|
|
637
|
-
}
|
|
638
|
-
function resolveCompositionPlan(source, target) {
|
|
639
|
-
const path = shortestPath(source, target);
|
|
640
|
-
if (path === void 0) return;
|
|
641
|
-
if (path.length > 4) return;
|
|
642
|
-
const hops = [];
|
|
643
|
-
for (let i = 0; i + 1 < path.length; i++) {
|
|
644
|
-
const from = path[i];
|
|
645
|
-
const to = path[i + 1];
|
|
646
|
-
if (from === void 0 || to === void 0) return;
|
|
647
|
-
const executor = to === "pdf" ? "toPdf" : from === "pdf" ? "fromPdf" : "bridge";
|
|
648
|
-
hops.push({
|
|
649
|
-
executor,
|
|
650
|
-
from,
|
|
651
|
-
to
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
return { hops };
|
|
655
|
-
}
|
|
656
|
-
function isContentFormat(format) {
|
|
657
|
-
return format !== "pdf" && format !== "odf";
|
|
658
|
-
}
|
|
659
|
-
function convertDocument(source, target, bytes, options) {
|
|
660
|
-
const plan = resolveCompositionPlan(source, target);
|
|
661
|
-
if (plan === void 0) throw new UnsupportedConversionError(source, target);
|
|
662
|
-
let current = bytes;
|
|
663
|
-
for (let i = 0; i < plan.hops.length; i++) {
|
|
664
|
-
const hop = plan.hops[i];
|
|
665
|
-
if (hop === void 0) throw new Error("convertDocument: resolveCompositionPlan returned a malformed hop");
|
|
666
|
-
const hopOptions = i === plan.hops.length - 1 ? options : options === void 0 ? void 0 : {
|
|
667
|
-
...options,
|
|
668
|
-
onDocument: void 0
|
|
669
|
-
};
|
|
670
|
-
if (hop.executor === "toPdf") {
|
|
671
|
-
if (!isContentFormat(hop.from)) throw new Error(`convertDocument: toPdf source '${hop.from}' is not a content format`);
|
|
672
|
-
current = executeToPdf(hop.from, current, hopOptions);
|
|
673
|
-
} else if (hop.executor === "fromPdf") {
|
|
674
|
-
if (!isContentFormat(hop.to)) throw new Error(`convertDocument: fromPdf target '${hop.to}' is not a content format`);
|
|
675
|
-
current = executeFromPdf(hop.to, current, hopOptions);
|
|
676
|
-
} else {
|
|
677
|
-
if (!isContentFormat(hop.from) || !isContentFormat(hop.to)) throw new Error(`convertDocument: bridge endpoints '${hop.from}' -> '${hop.to}' are not both content formats`);
|
|
678
|
-
current = executeBridge(hop.from, hop.to, current, hopOptions);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
return current;
|
|
682
|
-
}
|
|
683
|
-
//#endregion
|
|
684
|
-
//#region src/convert/convert.ts
|
|
685
|
-
const mathMetricsAt = (sizePt) => loadMathFont().metricsAt(sizePt);
|
|
686
|
-
function docxToPdf(bytes, options) {
|
|
687
|
-
return convertDocument("docx", "pdf", bytes, options);
|
|
688
|
-
}
|
|
689
|
-
function odtToPdf(bytes, options) {
|
|
690
|
-
return convertDocument("odt", "pdf", bytes, options);
|
|
691
|
-
}
|
|
692
|
-
function pptxToPdf(bytes, options) {
|
|
693
|
-
return convertDocument("pptx", "pdf", bytes, options);
|
|
694
|
-
}
|
|
695
|
-
function odpToPdf(bytes, options) {
|
|
696
|
-
return convertDocument("odp", "pdf", bytes, options);
|
|
697
|
-
}
|
|
698
|
-
function odsToPdf(bytes, options) {
|
|
699
|
-
return convertDocument("ods", "pdf", bytes, options);
|
|
700
|
-
}
|
|
701
|
-
function odgToPdf(bytes, options) {
|
|
702
|
-
return convertDocument("odg", "pdf", bytes, options);
|
|
703
|
-
}
|
|
704
|
-
function markdownToPdf(bytes, options) {
|
|
705
|
-
return convertDocument("markdown", "pdf", bytes, options);
|
|
706
|
-
}
|
|
707
|
-
const STANDALONE_FORMULA_SIZE_PT = 18;
|
|
708
|
-
const STANDALONE_FORMULA_MARGIN_PT = 72;
|
|
709
|
-
function odfToPdf(bytes, options) {
|
|
710
|
-
throwIfAborted(options?.signal);
|
|
711
|
-
const pkg = decodePackage$1(bytes);
|
|
712
|
-
const read = readOdfFormulaContent(pkg);
|
|
713
|
-
if (read.kind !== "formula") throw new Error("readOdfFormulaContent returned a non-formula ContentDocument");
|
|
714
|
-
const content = {
|
|
715
|
-
...read,
|
|
716
|
-
metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
|
|
717
|
-
};
|
|
718
|
-
const metrics = loadMathFont().metricsAt(STANDALONE_FORMULA_SIZE_PT);
|
|
719
|
-
const { box } = layoutFormula(content.formula.mathml, {
|
|
720
|
-
metrics,
|
|
721
|
-
sizePt: STANDALONE_FORMULA_SIZE_PT,
|
|
722
|
-
color: COLOR_BLACK
|
|
723
|
-
});
|
|
724
|
-
const flipped = flipY({
|
|
725
|
-
xPt: STANDALONE_FORMULA_MARGIN_PT,
|
|
726
|
-
yPt: STANDALONE_FORMULA_MARGIN_PT,
|
|
727
|
-
widthPt: box.widthPt,
|
|
728
|
-
heightPt: box.heightPt
|
|
729
|
-
}, PAGE_SIZE_A4.heightPt);
|
|
730
|
-
const layout = {
|
|
731
|
-
formatVersion: LAYOUT_FORMAT_VERSION,
|
|
732
|
-
metadata: content.metadata,
|
|
733
|
-
pages: [{
|
|
734
|
-
widthPt: PAGE_SIZE_A4.widthPt,
|
|
735
|
-
heightPt: PAGE_SIZE_A4.heightPt,
|
|
736
|
-
items: []
|
|
737
|
-
}],
|
|
738
|
-
images: {}
|
|
739
|
-
};
|
|
740
|
-
options?.onDocument?.({
|
|
741
|
-
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
742
|
-
content,
|
|
743
|
-
layout
|
|
744
|
-
});
|
|
745
|
-
throwIfAborted(options?.signal);
|
|
746
|
-
return writePdf(layout, {
|
|
747
|
-
signal: options?.signal,
|
|
748
|
-
formulas: [{
|
|
749
|
-
pageIndex: 0,
|
|
750
|
-
xPt: flipped.xPt,
|
|
751
|
-
yPt: flipped.yPt,
|
|
752
|
-
box
|
|
753
|
-
}]
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
function pdfToDocx(bytes, options) {
|
|
757
|
-
return convertDocument("pdf", "docx", bytes, options);
|
|
758
|
-
}
|
|
759
|
-
function pdfToPptx(bytes, options) {
|
|
760
|
-
return convertDocument("pdf", "pptx", bytes, options);
|
|
761
|
-
}
|
|
762
|
-
function pdfToOdt(bytes, options) {
|
|
763
|
-
return convertDocument("pdf", "odt", bytes, options);
|
|
764
|
-
}
|
|
765
|
-
function pdfToOdp(bytes, options) {
|
|
766
|
-
return convertDocument("pdf", "odp", bytes, options);
|
|
767
|
-
}
|
|
768
|
-
function pdfToOdg(bytes, options) {
|
|
769
|
-
return convertDocument("pdf", "odg", bytes, options);
|
|
770
|
-
}
|
|
771
|
-
function pdfToOds(bytes, options) {
|
|
772
|
-
return convertDocument("pdf", "ods", bytes, options);
|
|
773
|
-
}
|
|
774
|
-
function pdfToMarkdown(bytes, options) {
|
|
775
|
-
return convertDocument("pdf", "markdown", bytes, options);
|
|
776
|
-
}
|
|
777
|
-
function odtToDocx(bytes, options) {
|
|
778
|
-
return convertDocument("odt", "docx", bytes, options);
|
|
779
|
-
}
|
|
780
|
-
function docxToOdt(bytes, options) {
|
|
781
|
-
return convertDocument("docx", "odt", bytes, options);
|
|
782
|
-
}
|
|
783
|
-
function odpToPptx(bytes, options) {
|
|
784
|
-
return convertDocument("odp", "pptx", bytes, options);
|
|
785
|
-
}
|
|
786
|
-
function pptxToOdp(bytes, options) {
|
|
787
|
-
return convertDocument("pptx", "odp", bytes, options);
|
|
788
|
-
}
|
|
789
|
-
function odsToXlsx(bytes, options) {
|
|
790
|
-
return convertDocument("ods", "xlsx", bytes, options);
|
|
791
|
-
}
|
|
792
|
-
function xlsxToOds(bytes, options) {
|
|
793
|
-
return convertDocument("xlsx", "ods", bytes, options);
|
|
794
|
-
}
|
|
795
|
-
function markdownToDocx(bytes, options) {
|
|
796
|
-
return convertDocument("markdown", "docx", bytes, options);
|
|
797
|
-
}
|
|
798
|
-
function docxToMarkdown(bytes, options) {
|
|
799
|
-
return convertDocument("docx", "markdown", bytes, options);
|
|
800
|
-
}
|
|
801
|
-
function markdownToOdt(bytes, options) {
|
|
802
|
-
return convertDocument("markdown", "odt", bytes, options);
|
|
803
|
-
}
|
|
804
|
-
function odtToMarkdown(bytes, options) {
|
|
805
|
-
return convertDocument("odt", "markdown", bytes, options);
|
|
806
|
-
}
|
|
807
|
-
function docxToPptx(bytes, options) {
|
|
808
|
-
return convertDocument("docx", "pptx", bytes, options);
|
|
809
|
-
}
|
|
810
|
-
function pptxToDocx(bytes, options) {
|
|
811
|
-
return convertDocument("pptx", "docx", bytes, options);
|
|
812
|
-
}
|
|
813
|
-
function odtToOdp(bytes, options) {
|
|
814
|
-
return convertDocument("odt", "odp", bytes, options);
|
|
815
|
-
}
|
|
816
|
-
function odpToOdt(bytes, options) {
|
|
817
|
-
return convertDocument("odp", "odt", bytes, options);
|
|
818
|
-
}
|
|
819
|
-
function xlsxToPdf(bytes, options) {
|
|
820
|
-
return convertDocument("xlsx", "pdf", bytes, options);
|
|
821
|
-
}
|
|
822
|
-
function pdfToXlsx(bytes, options) {
|
|
823
|
-
return convertDocument("pdf", "xlsx", bytes, options);
|
|
824
|
-
}
|
|
825
|
-
function xlsxToMarkdown(bytes, options) {
|
|
826
|
-
return convertDocument("xlsx", "markdown", bytes, options);
|
|
827
|
-
}
|
|
828
|
-
function markdownToXlsx(bytes, options) {
|
|
829
|
-
return convertDocument("markdown", "xlsx", bytes, options);
|
|
830
|
-
}
|
|
831
|
-
var OdmUnresolvedSectionError = class extends Error {
|
|
832
|
-
hrefs;
|
|
833
|
-
constructor(hrefs) {
|
|
834
|
-
super(`odmToPdf: ${hrefs.length} chapter section(s) could not be resolved -- no inline content and no resolveSubDocument result for: ${hrefs.join(", ")}`);
|
|
835
|
-
this.name = "OdmUnresolvedSectionError";
|
|
836
|
-
this.hrefs = hrefs;
|
|
837
|
-
}
|
|
838
|
-
};
|
|
839
|
-
const INLINE_SECTION_MARGIN_PT = 56.69291338582677;
|
|
840
|
-
const INLINE_SECTION_MARGINS = {
|
|
841
|
-
topPt: INLINE_SECTION_MARGIN_PT,
|
|
842
|
-
rightPt: INLINE_SECTION_MARGIN_PT,
|
|
843
|
-
bottomPt: INLINE_SECTION_MARGIN_PT,
|
|
844
|
-
leftPt: INLINE_SECTION_MARGIN_PT
|
|
845
|
-
};
|
|
846
|
-
function inlineOdmSectionToContentSection(section, pkg) {
|
|
847
|
-
const blocks = [];
|
|
848
|
-
for (const node of section.inlineContent ?? []) {
|
|
849
|
-
if (node.type !== "element") continue;
|
|
850
|
-
if (node.tag === "text:p" || node.tag === "text:h") blocks.push(readOdfParagraph(node, pkg));
|
|
851
|
-
else if (node.tag === "table:table") blocks.push(readOdfTable(node, pkg));
|
|
852
|
-
}
|
|
853
|
-
return {
|
|
854
|
-
pageSize: PAGE_SIZE_A4,
|
|
855
|
-
margins: INLINE_SECTION_MARGINS,
|
|
856
|
-
blocks
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
function withLeadingChapterBreak(section) {
|
|
860
|
-
const pageBreak = { kind: "pageBreak" };
|
|
861
|
-
return {
|
|
862
|
-
...section,
|
|
863
|
-
blocks: [pageBreak, ...section.blocks]
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
function odmToPdf(bytes, options) {
|
|
867
|
-
throwIfAborted(options?.signal);
|
|
868
|
-
const pkg = decodePackage$1(bytes);
|
|
869
|
-
const odm = readOdm(pkg);
|
|
870
|
-
const unresolvedHrefs = [];
|
|
871
|
-
const chapterSections = [];
|
|
872
|
-
const sourceFonts = extractSourceFonts({
|
|
873
|
-
kind: "odf",
|
|
874
|
-
package: pkg
|
|
875
|
-
});
|
|
876
|
-
for (const section of odm.sections) {
|
|
877
|
-
throwIfAborted(options?.signal);
|
|
878
|
-
if (section.inlineContent !== void 0) {
|
|
879
|
-
chapterSections.push([inlineOdmSectionToContentSection(section, pkg)]);
|
|
880
|
-
continue;
|
|
881
|
-
}
|
|
882
|
-
const chapterBytes = options?.resolveSubDocument?.(section.href);
|
|
883
|
-
if (chapterBytes === void 0) {
|
|
884
|
-
unresolvedHrefs.push(section.href);
|
|
885
|
-
continue;
|
|
886
|
-
}
|
|
887
|
-
const chapterPkg = decodePackage$1(chapterBytes);
|
|
888
|
-
sourceFonts.push(...extractSourceFonts({
|
|
889
|
-
kind: "odf",
|
|
890
|
-
package: chapterPkg
|
|
891
|
-
}));
|
|
892
|
-
const chapterContent = readOdtContent(chapterPkg);
|
|
893
|
-
if (chapterContent.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
|
|
894
|
-
chapterSections.push(chapterContent.sections);
|
|
895
|
-
}
|
|
896
|
-
if (unresolvedHrefs.length > 0) throw new OdmUnresolvedSectionError(unresolvedHrefs);
|
|
897
|
-
const combinedSections = [];
|
|
898
|
-
chapterSections.forEach((sections, chapterIndex) => {
|
|
899
|
-
if (chapterIndex === 0) {
|
|
900
|
-
combinedSections.push(...sections);
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
combinedSections.push(...sections.map((section, sectionIndex) => sectionIndex === 0 ? withLeadingChapterBreak(section) : section));
|
|
904
|
-
});
|
|
905
|
-
throwIfAborted(options?.signal);
|
|
906
|
-
const content = {
|
|
907
|
-
kind: "wordprocessing",
|
|
908
|
-
formatVersion: CONTENT_FORMAT_VERSION,
|
|
909
|
-
metadata: resolveMetadataTimestamps(readOdfMetadata(pkg), options?.clock),
|
|
910
|
-
sections: combinedSections
|
|
911
|
-
};
|
|
912
|
-
const fonts = createFontRegistry({
|
|
913
|
-
sourceFonts,
|
|
914
|
-
fonts: options?.fonts,
|
|
915
|
-
onSubstitution: options?.onFontSubstitution
|
|
916
|
-
});
|
|
917
|
-
const { document: layout, formulas } = convertWordprocessingToLayout(content, {
|
|
918
|
-
measurer: createFontMeasurer(fonts),
|
|
919
|
-
mathMetricsAt
|
|
920
|
-
});
|
|
921
|
-
return writePdf(layout, {
|
|
922
|
-
signal: options?.signal,
|
|
923
|
-
onSubstitution: options?.onSubstitution,
|
|
924
|
-
formulas,
|
|
925
|
-
fonts
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
function odbToXlsx(bytes, options) {
|
|
929
|
-
throwIfAborted(options?.signal);
|
|
930
|
-
const pkg = decodePackage$1(bytes);
|
|
931
|
-
const tables = readOdbTables(pkg, { timeZone: options?.timeZone });
|
|
932
|
-
throwIfAborted(options?.signal);
|
|
933
|
-
const content = odbTablesToSpreadsheetDocument(tables);
|
|
934
|
-
return encodePackage(buildXlsxPackage(content));
|
|
935
|
-
}
|
|
936
|
-
function odbToCsv(bytes, options) {
|
|
937
|
-
throwIfAborted(options?.signal);
|
|
938
|
-
const pkg = decodePackage$1(bytes);
|
|
939
|
-
const tables = readOdbTables(pkg, { timeZone: options?.timeZone });
|
|
940
|
-
throwIfAborted(options?.signal);
|
|
941
|
-
return buildOdbTableCsv(tables, options?.table);
|
|
942
|
-
}
|
|
943
|
-
function odbReportToDocx(content, options) {
|
|
944
|
-
throwIfAborted(options?.signal);
|
|
945
|
-
return encodePackage(buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
|
|
946
|
-
}
|
|
947
|
-
function odbReportToOdt(content, options) {
|
|
948
|
-
throwIfAborted(options?.signal);
|
|
949
|
-
return encodePackage$1(buildOdtPackage(content));
|
|
950
|
-
}
|
|
951
|
-
function odbReportToPdf(content, options) {
|
|
952
|
-
throwIfAborted(options?.signal);
|
|
953
|
-
if (content.kind !== "wordprocessing") throw new Error("odbReportToPdf requires a wordprocessing ContentDocument");
|
|
954
|
-
const fonts = createFontRegistry({
|
|
955
|
-
fonts: options?.fonts,
|
|
956
|
-
onSubstitution: options?.onFontSubstitution
|
|
957
|
-
});
|
|
958
|
-
const { document: layout, formulas } = convertWordprocessingToLayout(content, {
|
|
959
|
-
measurer: createFontMeasurer(fonts),
|
|
960
|
-
mathMetricsAt
|
|
961
|
-
});
|
|
962
|
-
options?.onDocument?.({
|
|
963
|
-
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
964
|
-
content,
|
|
965
|
-
layout
|
|
966
|
-
});
|
|
967
|
-
return writePdf(layout, {
|
|
968
|
-
signal: options?.signal,
|
|
969
|
-
onSubstitution: options?.onSubstitution,
|
|
970
|
-
formulas,
|
|
971
|
-
fonts
|
|
972
|
-
});
|
|
973
|
-
}
|
|
974
|
-
//#endregion
|
|
975
|
-
export { pdfToOdg as A, xlsxToOds as B, odsToXlsx as C, odtToPdf as D, odtToOdp as E, pdfToXlsx as F, DIRECT_EDGES as G, FORMAT_NODES as H, pptxToDocx as I, resolveConversionPath as J, FORMAT_CAPABILITIES as K, pptxToOdp as L, pdfToOds as M, pdfToOdt as N, pdfToDocx as O, pdfToPptx as P, pptxToPdf as R, odsToPdf as S, odtToMarkdown as T, convertDocument as U, xlsxToPdf as V, resolveCompositionPlan as W, odgToPdf as _, docxToPptx as a, odpToPdf as b, markdownToOdt as c, odbReportToDocx as d, odbReportToOdt as f, odfToPdf as g, odbToXlsx as h, docxToPdf as i, pdfToOdp as j, pdfToMarkdown as k, markdownToPdf as l, odbToCsv as m, docxToMarkdown as n, inlineOdmSectionToContentSection as o, odbReportToPdf as p, UnsupportedConversionError as q, docxToOdt as r, markdownToDocx as s, OdmUnresolvedSectionError as t, markdownToXlsx as u, odmToPdf as v, odtToDocx as w, odpToPptx as x, odpToOdt as y, xlsxToMarkdown as z };
|