documents.js 1.97.10 → 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.
Files changed (39) hide show
  1. package/dist/capability-DX0lCSiI.d.ts +16 -0
  2. package/dist/capability-an5gSNsu.d.cts +16 -0
  3. package/dist/convert/capability.cjs +0 -207
  4. package/dist/convert/capability.d.cts +2 -38
  5. package/dist/convert/capability.d.ts +2 -38
  6. package/dist/convert/capability.js +1 -206
  7. package/dist/convert/composition.cjs +415 -0
  8. package/dist/convert/composition.d.cts +60 -0
  9. package/dist/convert/composition.d.ts +60 -0
  10. package/dist/convert/composition.js +412 -0
  11. package/dist/convert/convert.cjs +33 -480
  12. package/dist/convert/convert.d.cts +3 -3
  13. package/dist/convert/convert.d.ts +2 -2
  14. package/dist/convert/convert.js +36 -483
  15. package/dist/convert/local.cjs +33 -33
  16. package/dist/convert/local.js +34 -34
  17. package/dist/fonts/registry.d.cts +19 -1
  18. package/dist/fonts/registry.d.ts +19 -1
  19. package/dist/hsqldb/binary-script.d.cts +1 -1
  20. package/dist/hsqldb/binary-script.d.ts +1 -1
  21. package/dist/hsqldb/cache.d.cts +1 -1
  22. package/dist/hsqldb/cache.d.ts +1 -1
  23. package/dist/hsqldb/rowformat.d.cts +24 -1
  24. package/dist/hsqldb/rowformat.d.ts +24 -1
  25. package/dist/index.cjs +4 -1
  26. package/dist/index.d.cts +7 -6
  27. package/dist/index.d.ts +5 -4
  28. package/dist/index.js +3 -2
  29. package/dist/odb/read.d.cts +1 -1
  30. package/dist/odb/read.d.ts +1 -1
  31. package/dist/odb/report/content.d.cts +1 -1
  32. package/dist/odb/report/content.d.ts +1 -1
  33. package/dist/odb/report/source.d.cts +1 -1
  34. package/dist/odb/report/source.d.ts +1 -1
  35. package/package.json +1 -1
  36. package/dist/registry-DpF4A9EM.d.ts +0 -20
  37. package/dist/registry-ZAWlWHqJ.d.cts +0 -20
  38. package/dist/rowformat-Cl2exlEh.d.cts +0 -25
  39. package/dist/rowformat-Cl2exlEh.d.ts +0 -25
@@ -1,237 +1,43 @@
1
1
  import { flipY } from "../model/geometry.js";
2
2
  import { resolveMetadataTimestamps } from "../model/metadata.js";
3
- import { openDocx } from "../edit/docx/editor.js";
4
3
  import { buildDocxPackage } from "../edit/docx/content.js";
5
- import { openPptx } from "../edit/pptx/editor.js";
6
- import { buildPptxPackage } from "../edit/pptx/content.js";
7
4
  import { buildOdtPackage } from "../edit/odt/content.js";
8
- import { buildOdpPackage } from "../edit/odp/content.js";
9
- import { buildOdsPackage } from "../edit/ods/content.js";
10
- import { buildOdgPackage } from "../edit/odg/content.js";
11
- import { readMarkdownContent } from "../markdown/read.js";
12
- import { buildMarkdownText } from "../markdown/write.js";
13
- import { createDocumentFontRegistry, extractSourceFonts } from "../fonts/registry.js";
5
+ import { extractSourceFonts } from "../fonts/registry.js";
14
6
  import { layoutFormula } from "../mathml/layout.js";
15
- import { readDocxContent } from "../ooxml/docx/read.js";
16
- import { readPptxContent } from "../ooxml/pptx/read.js";
17
7
  import { readOdfFormulaContent } from "../odf/formula/read.js";
18
8
  import { readOdtContent } from "../odf/odt/read.js";
19
- import { readOdpContent } from "../odf/odp/read.js";
20
- import { readOdsContent } from "../odf/ods/read.js";
21
- import { readOdgContent } from "../odf/odg/read.js";
22
- import { decodeMarkdownText, encodeMarkdownText } from "../markdown/text.js";
23
9
  import { convertWordprocessingToLayout } from "../layout/engine.js";
24
- import { convertPresentationToLayout } from "../layout/slides.js";
25
10
  import { throwIfAborted } from "../ports/abort.js";
26
- import { convertSpreadsheetToLayout } from "../layout/sheets.js";
27
- import { convertDrawingToLayout } from "../layout/drawing.js";
28
- import { reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing } from "../layout/reconstruct.js";
29
11
  import { buildOdbTableCsv } from "../odb/csv.js";
30
12
  import { readOdbTables } from "../odb/read.js";
31
13
  import { odbTablesToSpreadsheetDocument } from "../odb/spreadsheet.js";
32
- import { presentationToWordprocessing, wordprocessingToPresentation } from "./variant-bridges.js";
33
- import { buildXlsxPackage, decodePackage, encodePackage, readXlsxContent } from "ooxml.js";
14
+ import { convertDocument } from "./composition.js";
15
+ import { buildXlsxPackage, encodePackage } from "ooxml.js";
34
16
  import { COLOR_BLACK, CONTENT_FORMAT_VERSION, DOCUMENT_PACKAGE_FORMAT_VERSION, LAYOUT_FORMAT_VERSION, PAGE_SIZE_A4 } from "document-schema.js";
35
17
  import { decodePackage as decodePackage$1, encodePackage as encodePackage$1, readOdfMetadata, readOdfParagraph, readOdfTable, readOdm } from "odf.js";
36
- import { createFontMeasurer, createFontRegistry, loadMathFont, readPdf, writePdf } from "pdf-codec";
18
+ import { createFontMeasurer, createFontRegistry, loadMathFont, writePdf } from "pdf-codec";
37
19
  //#region src/convert/convert.ts
38
20
  const mathMetricsAt = (sizePt) => loadMathFont().metricsAt(sizePt);
39
21
  function docxToPdf(bytes, options) {
40
- const pkg = openDocx(bytes).toPackage();
41
- const read = readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic });
42
- if (read.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
43
- const content = {
44
- ...read,
45
- metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
46
- };
47
- const fonts = createDocumentFontRegistry({
48
- kind: "docx",
49
- package: pkg
50
- }, options);
51
- const { document: layout, formulas } = convertWordprocessingToLayout(content, {
52
- measurer: createFontMeasurer(fonts),
53
- mathMetricsAt
54
- });
55
- options?.onDocument?.({
56
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
57
- content,
58
- layout
59
- });
60
- return writePdf(layout, {
61
- signal: options?.signal,
62
- onSubstitution: options?.onSubstitution,
63
- formulas,
64
- fonts
65
- });
22
+ return convertDocument("docx", "pdf", bytes, options);
66
23
  }
67
24
  function odtToPdf(bytes, options) {
68
- const pkg = decodePackage$1(bytes);
69
- const read = readOdtContent(pkg);
70
- if (read.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
71
- const content = {
72
- ...read,
73
- metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
74
- };
75
- const fonts = createDocumentFontRegistry({
76
- kind: "odf",
77
- package: pkg
78
- }, options);
79
- const { document: layout, formulas } = convertWordprocessingToLayout(content, {
80
- measurer: createFontMeasurer(fonts),
81
- mathMetricsAt
82
- });
83
- options?.onDocument?.({
84
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
85
- content,
86
- layout
87
- });
88
- return writePdf(layout, {
89
- signal: options?.signal,
90
- onSubstitution: options?.onSubstitution,
91
- formulas,
92
- fonts
93
- });
25
+ return convertDocument("odt", "pdf", bytes, options);
94
26
  }
95
27
  function pptxToPdf(bytes, options) {
96
- const pkg = openPptx(bytes).toPackage();
97
- const read = readPptxContent(pkg);
98
- if (read.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
99
- const content = {
100
- ...read,
101
- metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
102
- };
103
- const fonts = createDocumentFontRegistry({
104
- kind: "pptx",
105
- package: pkg
106
- }, options);
107
- const { document: layout, formulas } = convertPresentationToLayout(content, {
108
- measurer: createFontMeasurer(fonts),
109
- mathMetricsAt
110
- });
111
- options?.onDocument?.({
112
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
113
- content,
114
- layout
115
- });
116
- return writePdf(layout, {
117
- signal: options?.signal,
118
- onSubstitution: options?.onSubstitution,
119
- formulas,
120
- fonts
121
- });
28
+ return convertDocument("pptx", "pdf", bytes, options);
122
29
  }
123
30
  function odpToPdf(bytes, options) {
124
- const pkg = decodePackage$1(bytes);
125
- const read = readOdpContent(pkg);
126
- if (read.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
127
- const content = {
128
- ...read,
129
- metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
130
- };
131
- const fonts = createDocumentFontRegistry({
132
- kind: "odf",
133
- package: pkg
134
- }, options);
135
- const { document: layout, formulas } = convertPresentationToLayout(content, {
136
- measurer: createFontMeasurer(fonts),
137
- mathMetricsAt
138
- });
139
- options?.onDocument?.({
140
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
141
- content,
142
- layout
143
- });
144
- return writePdf(layout, {
145
- signal: options?.signal,
146
- onSubstitution: options?.onSubstitution,
147
- formulas,
148
- fonts
149
- });
31
+ return convertDocument("odp", "pdf", bytes, options);
150
32
  }
151
33
  function odsToPdf(bytes, options) {
152
- const pkg = decodePackage$1(bytes);
153
- const read = readOdsContent(pkg);
154
- if (read.kind !== "spreadsheet") throw new Error("readOdsContent returned a non-spreadsheet ContentDocument");
155
- const content = {
156
- ...read,
157
- metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
158
- };
159
- const fonts = createDocumentFontRegistry({
160
- kind: "odf",
161
- package: pkg
162
- }, options);
163
- const { document: layout, formulas } = convertSpreadsheetToLayout(content, {
164
- measurer: createFontMeasurer(fonts),
165
- mathMetricsAt,
166
- signal: options?.signal
167
- });
168
- options?.onDocument?.({
169
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
170
- content,
171
- layout
172
- });
173
- return writePdf(layout, {
174
- signal: options?.signal,
175
- onSubstitution: options?.onSubstitution,
176
- formulas,
177
- fonts
178
- });
34
+ return convertDocument("ods", "pdf", bytes, options);
179
35
  }
180
36
  function odgToPdf(bytes, options) {
181
- const pkg = decodePackage$1(bytes);
182
- const read = readOdgContent(pkg);
183
- if (read.kind !== "drawing") throw new Error("readOdgContent returned a non-drawing ContentDocument");
184
- const content = {
185
- ...read,
186
- metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
187
- };
188
- const fonts = createDocumentFontRegistry({
189
- kind: "odf",
190
- package: pkg
191
- }, options);
192
- const layout = convertDrawingToLayout(content, { measurer: createFontMeasurer(fonts) });
193
- options?.onDocument?.({
194
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
195
- content,
196
- layout
197
- });
198
- return writePdf(layout, {
199
- signal: options?.signal,
200
- onSubstitution: options?.onSubstitution,
201
- fonts
202
- });
37
+ return convertDocument("odg", "pdf", bytes, options);
203
38
  }
204
39
  function markdownToPdf(bytes, options) {
205
- throwIfAborted(options?.signal);
206
- const text = decodeMarkdownText(bytes);
207
- const read = readMarkdownContent(text, {
208
- signal: options?.signal,
209
- images: options?.images
210
- });
211
- if (read.kind !== "wordprocessing") throw new Error("readMarkdownContent returned a non-wordprocessing ContentDocument");
212
- const content = {
213
- ...read,
214
- metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
215
- };
216
- const fonts = createFontRegistry({
217
- fonts: options?.fonts,
218
- onSubstitution: options?.onFontSubstitution
219
- });
220
- const { document: layout, formulas } = convertWordprocessingToLayout(content, {
221
- measurer: createFontMeasurer(fonts),
222
- mathMetricsAt
223
- });
224
- options?.onDocument?.({
225
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
226
- content,
227
- layout
228
- });
229
- return writePdf(layout, {
230
- signal: options?.signal,
231
- onSubstitution: options?.onSubstitution,
232
- formulas,
233
- fonts
234
- });
40
+ return convertDocument("markdown", "pdf", bytes, options);
235
41
  }
236
42
  const STANDALONE_FORMULA_SIZE_PT = 18;
237
43
  const STANDALONE_FORMULA_MARGIN_PT = 72;
@@ -283,332 +89,79 @@ function odfToPdf(bytes, options) {
283
89
  });
284
90
  }
285
91
  function pdfToDocx(bytes, options) {
286
- const layout = readPdf(bytes, {
287
- signal: options?.signal,
288
- sink: options?.sink
289
- });
290
- const content = reconstructWordprocessing(layout, { signal: options?.signal });
291
- options?.onDocument?.({
292
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
293
- content,
294
- layout
295
- });
296
- return encodePackage(buildDocxPackage(content));
92
+ return convertDocument("pdf", "docx", bytes, options);
297
93
  }
298
94
  function pdfToPptx(bytes, options) {
299
- const layout = readPdf(bytes, {
300
- signal: options?.signal,
301
- sink: options?.sink
302
- });
303
- const content = reconstructPresentation(layout, { signal: options?.signal });
304
- options?.onDocument?.({
305
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
306
- content,
307
- layout
308
- });
309
- return encodePackage(buildPptxPackage(content));
95
+ return convertDocument("pdf", "pptx", bytes, options);
310
96
  }
311
97
  function pdfToOdt(bytes, options) {
312
- const layout = readPdf(bytes, {
313
- signal: options?.signal,
314
- sink: options?.sink
315
- });
316
- const content = reconstructWordprocessing(layout, { signal: options?.signal });
317
- options?.onDocument?.({
318
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
319
- content,
320
- layout
321
- });
322
- return encodePackage$1(buildOdtPackage(content));
98
+ return convertDocument("pdf", "odt", bytes, options);
323
99
  }
324
100
  function pdfToOdp(bytes, options) {
325
- const layout = readPdf(bytes, {
326
- signal: options?.signal,
327
- sink: options?.sink
328
- });
329
- const content = reconstructPresentation(layout, { signal: options?.signal });
330
- options?.onDocument?.({
331
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
332
- content,
333
- layout
334
- });
335
- return encodePackage$1(buildOdpPackage(content));
101
+ return convertDocument("pdf", "odp", bytes, options);
336
102
  }
337
103
  function pdfToOdg(bytes, options) {
338
- const layout = readPdf(bytes, {
339
- signal: options?.signal,
340
- sink: options?.sink
341
- });
342
- const content = reconstructDrawing(layout, { signal: options?.signal });
343
- options?.onDocument?.({
344
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
345
- content,
346
- layout
347
- });
348
- return encodePackage$1(buildOdgPackage(content));
104
+ return convertDocument("pdf", "odg", bytes, options);
349
105
  }
350
106
  function pdfToOds(bytes, options) {
351
- const layout = readPdf(bytes, {
352
- signal: options?.signal,
353
- sink: options?.sink
354
- });
355
- const content = reconstructSpreadsheet(layout, { signal: options?.signal });
356
- options?.onDocument?.({
357
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
358
- content,
359
- layout
360
- });
361
- return encodePackage$1(buildOdsPackage(content));
107
+ return convertDocument("pdf", "ods", bytes, options);
362
108
  }
363
109
  function pdfToMarkdown(bytes, options) {
364
- const layout = readPdf(bytes, {
365
- signal: options?.signal,
366
- sink: options?.sink
367
- });
368
- const content = reconstructWordprocessing(layout, { signal: options?.signal });
369
- options?.onDocument?.({
370
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
371
- content,
372
- layout
373
- });
374
- const text = buildMarkdownText(content);
375
- return encodeMarkdownText(text);
110
+ return convertDocument("pdf", "markdown", bytes, options);
376
111
  }
377
112
  function odtToDocx(bytes, options) {
378
- throwIfAborted(options?.signal);
379
- const pkg = decodePackage$1(bytes);
380
- const content = readOdtContent(pkg);
381
- if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
382
- throwIfAborted(options?.signal);
383
- options?.onDocument?.({
384
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
385
- content
386
- });
387
- return encodePackage(buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
113
+ return convertDocument("odt", "docx", bytes, options);
388
114
  }
389
115
  function docxToOdt(bytes, options) {
390
- throwIfAborted(options?.signal);
391
- const pkg = decodePackage(bytes);
392
- const content = readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic });
393
- if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
394
- throwIfAborted(options?.signal);
395
- options?.onDocument?.({
396
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
397
- content
398
- });
399
- return encodePackage$1(buildOdtPackage(content));
116
+ return convertDocument("docx", "odt", bytes, options);
400
117
  }
401
118
  function odpToPptx(bytes, options) {
402
- throwIfAborted(options?.signal);
403
- const pkg = decodePackage$1(bytes);
404
- const content = readOdpContent(pkg);
405
- if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
406
- throwIfAborted(options?.signal);
407
- options?.onDocument?.({
408
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
409
- content
410
- });
411
- return encodePackage(buildPptxPackage(content));
119
+ return convertDocument("odp", "pptx", bytes, options);
412
120
  }
413
121
  function pptxToOdp(bytes, options) {
414
- throwIfAborted(options?.signal);
415
- const pkg = decodePackage(bytes);
416
- const content = readPptxContent(pkg);
417
- if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
418
- throwIfAborted(options?.signal);
419
- options?.onDocument?.({
420
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
421
- content
422
- });
423
- return encodePackage$1(buildOdpPackage(content));
122
+ return convertDocument("pptx", "odp", bytes, options);
424
123
  }
425
124
  function odsToXlsx(bytes, options) {
426
- throwIfAborted(options?.signal);
427
- const pkg = decodePackage$1(bytes);
428
- const content = readOdsContent(pkg);
429
- if (content.kind !== "spreadsheet") throw new Error("readOdsContent returned a non-spreadsheet ContentDocument");
430
- throwIfAborted(options?.signal);
431
- options?.onDocument?.({
432
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
433
- content
434
- });
435
- return encodePackage(buildXlsxPackage(content));
125
+ return convertDocument("ods", "xlsx", bytes, options);
436
126
  }
437
127
  function xlsxToOds(bytes, options) {
438
- throwIfAborted(options?.signal);
439
- const pkg = decodePackage(bytes);
440
- const content = readXlsxContent(pkg);
441
- if (content.kind !== "spreadsheet") throw new Error("readXlsxContent returned a non-spreadsheet ContentDocument");
442
- throwIfAborted(options?.signal);
443
- options?.onDocument?.({
444
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
445
- content
446
- });
447
- return encodePackage$1(buildOdsPackage(content));
128
+ return convertDocument("xlsx", "ods", bytes, options);
448
129
  }
449
130
  function markdownToDocx(bytes, options) {
450
- throwIfAborted(options?.signal);
451
- const text = decodeMarkdownText(bytes);
452
- const content = readMarkdownContent(text, {
453
- signal: options?.signal,
454
- images: options?.images
455
- });
456
- if (content.kind !== "wordprocessing") throw new Error("readMarkdownContent returned a non-wordprocessing ContentDocument");
457
- throwIfAborted(options?.signal);
458
- options?.onDocument?.({
459
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
460
- content
461
- });
462
- return encodePackage(buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
131
+ return convertDocument("markdown", "docx", bytes, options);
463
132
  }
464
133
  function docxToMarkdown(bytes, options) {
465
- throwIfAborted(options?.signal);
466
- const pkg = decodePackage(bytes);
467
- const content = readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic });
468
- if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
469
- throwIfAborted(options?.signal);
470
- options?.onDocument?.({
471
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
472
- content
473
- });
474
- const text = buildMarkdownText(content);
475
- return encodeMarkdownText(text);
134
+ return convertDocument("docx", "markdown", bytes, options);
476
135
  }
477
136
  function markdownToOdt(bytes, options) {
478
- throwIfAborted(options?.signal);
479
- const text = decodeMarkdownText(bytes);
480
- const content = readMarkdownContent(text, {
481
- signal: options?.signal,
482
- images: options?.images
483
- });
484
- if (content.kind !== "wordprocessing") throw new Error("readMarkdownContent returned a non-wordprocessing ContentDocument");
485
- throwIfAborted(options?.signal);
486
- options?.onDocument?.({
487
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
488
- content
489
- });
490
- return encodePackage$1(buildOdtPackage(content));
137
+ return convertDocument("markdown", "odt", bytes, options);
491
138
  }
492
139
  function odtToMarkdown(bytes, options) {
493
- throwIfAborted(options?.signal);
494
- const pkg = decodePackage$1(bytes);
495
- const content = readOdtContent(pkg);
496
- if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
497
- throwIfAborted(options?.signal);
498
- options?.onDocument?.({
499
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
500
- content
501
- });
502
- const text = buildMarkdownText(content);
503
- return encodeMarkdownText(text);
140
+ return convertDocument("odt", "markdown", bytes, options);
504
141
  }
505
142
  function docxToPptx(bytes, options) {
506
- throwIfAborted(options?.signal);
507
- const content = readDocxContent(decodePackage$1(bytes));
508
- if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
509
- const presentation = wordprocessingToPresentation(content);
510
- throwIfAborted(options?.signal);
511
- options?.onDocument?.({
512
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
513
- content: presentation
514
- });
515
- return encodePackage(buildPptxPackage(presentation));
143
+ return convertDocument("docx", "pptx", bytes, options);
516
144
  }
517
145
  function pptxToDocx(bytes, options) {
518
- throwIfAborted(options?.signal);
519
- const content = readPptxContent(decodePackage$1(bytes));
520
- if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
521
- const wordprocessing = presentationToWordprocessing(content);
522
- throwIfAborted(options?.signal);
523
- options?.onDocument?.({
524
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
525
- content: wordprocessing
526
- });
527
- return encodePackage(buildDocxPackage(wordprocessing, { onMathDiagnostic: options?.onMathDiagnostic }));
146
+ return convertDocument("pptx", "docx", bytes, options);
528
147
  }
529
148
  function odtToOdp(bytes, options) {
530
- throwIfAborted(options?.signal);
531
- const pkg = decodePackage$1(bytes);
532
- const content = readOdtContent(pkg);
533
- if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
534
- const presentation = wordprocessingToPresentation(content);
535
- throwIfAborted(options?.signal);
536
- options?.onDocument?.({
537
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
538
- content: presentation
539
- });
540
- return encodePackage(buildOdpPackage(presentation));
149
+ return convertDocument("odt", "odp", bytes, options);
541
150
  }
542
151
  function odpToOdt(bytes, options) {
543
- throwIfAborted(options?.signal);
544
- const pkg = decodePackage$1(bytes);
545
- const content = readOdpContent(pkg);
546
- if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
547
- const wordprocessing = presentationToWordprocessing(content);
548
- throwIfAborted(options?.signal);
549
- options?.onDocument?.({
550
- formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
551
- content: wordprocessing
552
- });
553
- return encodePackage(buildOdtPackage(wordprocessing));
152
+ return convertDocument("odp", "odt", bytes, options);
554
153
  }
555
154
  function xlsxToPdf(bytes, options) {
556
- throwIfAborted(options?.signal);
557
- const odsBytes = xlsxToOds(bytes, { signal: options?.signal });
558
- throwIfAborted(options?.signal);
559
- return odsToPdf(odsBytes, {
560
- signal: options?.signal,
561
- onSubstitution: options?.onSubstitution,
562
- onDocument: options?.onDocument,
563
- fonts: options?.fonts,
564
- onFontSubstitution: options?.onFontSubstitution,
565
- clock: options?.clock
566
- });
155
+ return convertDocument("xlsx", "pdf", bytes, options);
567
156
  }
568
157
  function pdfToXlsx(bytes, options) {
569
- throwIfAborted(options?.signal);
570
- const odsBytes = pdfToOds(bytes, {
571
- signal: options?.signal,
572
- sink: options?.sink
573
- });
574
- throwIfAborted(options?.signal);
575
- return odsToXlsx(odsBytes, {
576
- signal: options?.signal,
577
- onDocument: options?.onDocument
578
- });
158
+ return convertDocument("pdf", "xlsx", bytes, options);
579
159
  }
580
160
  function xlsxToMarkdown(bytes, options) {
581
- throwIfAborted(options?.signal);
582
- const pdfBytes = xlsxToPdf(bytes, {
583
- signal: options?.signal,
584
- fonts: options?.fonts,
585
- onFontSubstitution: options?.onFontSubstitution,
586
- onSubstitution: options?.onSubstitution,
587
- clock: options?.clock
588
- });
589
- throwIfAborted(options?.signal);
590
- return pdfToMarkdown(pdfBytes, {
591
- signal: options?.signal,
592
- sink: options?.sink,
593
- onDocument: options?.onDocument
594
- });
161
+ return convertDocument("xlsx", "markdown", bytes, options);
595
162
  }
596
163
  function markdownToXlsx(bytes, options) {
597
- throwIfAborted(options?.signal);
598
- const pdfBytes = markdownToPdf(bytes, {
599
- signal: options?.signal,
600
- fonts: options?.fonts,
601
- onFontSubstitution: options?.onFontSubstitution,
602
- onSubstitution: options?.onSubstitution,
603
- clock: options?.clock,
604
- images: options?.images
605
- });
606
- throwIfAborted(options?.signal);
607
- return pdfToXlsx(pdfBytes, {
608
- signal: options?.signal,
609
- sink: options?.sink,
610
- onDocument: options?.onDocument
611
- });
164
+ return convertDocument("markdown", "xlsx", bytes, options);
612
165
  }
613
166
  var OdmUnresolvedSectionError = class extends Error {
614
167
  hrefs;