js.documents 1.97.9 → 1.97.11
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/convert/capability.cjs +5 -272
- package/dist/convert/capability.d.cts +1 -1
- package/dist/convert/capability.d.ts +1 -1
- package/dist/convert/capability.js +1 -268
- package/dist/convert/codec.cjs +29 -29
- package/dist/convert/codec.js +1 -1
- package/dist/convert/composition.cjs +5 -0
- package/dist/convert/composition.d.cts +60 -0
- package/dist/convert/composition.d.ts +60 -0
- package/dist/convert/composition.js +2 -0
- package/dist/convert/convert.cjs +42 -797
- package/dist/convert/convert.d.cts +1 -105
- package/dist/convert/convert.d.ts +1 -105
- package/dist/convert/convert.js +1 -756
- package/dist/convert/local.cjs +16 -31
- package/dist/convert/local.js +15 -30
- package/dist/convert-B1izrvnQ.d.cts +106 -0
- package/dist/convert-BO_4tCwz.cjs +1262 -0
- package/dist/convert-HYsWA-LI.d.ts +106 -0
- package/dist/convert-ULGgwmSb.js +975 -0
- package/dist/index.cjs +42 -42
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/metadata/read.cjs +2 -2
- package/dist/metadata/read.js +1 -1
- package/package.json +1 -1
package/dist/convert/convert.js
CHANGED
|
@@ -1,757 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { resolveMetadataTimestamps } from "../model/metadata.js";
|
|
3
|
-
import { openDocx } from "../edit/docx/editor.js";
|
|
4
|
-
import { buildDocxPackage } from "../edit/docx/content.js";
|
|
5
|
-
import { openPptx } from "../edit/pptx/editor.js";
|
|
6
|
-
import { buildPptxPackage } from "../edit/pptx/content.js";
|
|
7
|
-
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";
|
|
14
|
-
import { layoutFormula } from "../mathml/layout.js";
|
|
15
|
-
import { readDocxContent } from "../ooxml/docx/read.js";
|
|
16
|
-
import { readPptxContent } from "../ooxml/pptx/read.js";
|
|
17
|
-
import { readOdfFormulaContent } from "../odf/formula/read.js";
|
|
18
|
-
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
|
-
import { convertWordprocessingToLayout } from "../layout/engine.js";
|
|
24
|
-
import { convertPresentationToLayout } from "../layout/slides.js";
|
|
25
|
-
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
|
-
import { buildOdbTableCsv } from "../odb/csv.js";
|
|
30
|
-
import { readOdbTables } from "../odb/read.js";
|
|
31
|
-
import { odbTablesToSpreadsheetDocument } from "../odb/spreadsheet.js";
|
|
32
|
-
import { presentationToWordprocessing, wordprocessingToPresentation } from "./variant-bridges.js";
|
|
33
|
-
import { buildXlsxPackage, decodePackage, encodePackage, readXlsxContent } from "ooxml.js";
|
|
34
|
-
import { COLOR_BLACK, CONTENT_FORMAT_VERSION, DOCUMENT_PACKAGE_FORMAT_VERSION, LAYOUT_FORMAT_VERSION, PAGE_SIZE_A4 } from "document-schema.js";
|
|
35
|
-
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";
|
|
37
|
-
//#region src/convert/convert.ts
|
|
38
|
-
const mathMetricsAt = (sizePt) => loadMathFont().metricsAt(sizePt);
|
|
39
|
-
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
|
-
});
|
|
66
|
-
}
|
|
67
|
-
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
|
-
});
|
|
94
|
-
}
|
|
95
|
-
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
|
-
});
|
|
122
|
-
}
|
|
123
|
-
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
|
-
});
|
|
150
|
-
}
|
|
151
|
-
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
|
-
});
|
|
179
|
-
}
|
|
180
|
-
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
|
-
});
|
|
203
|
-
}
|
|
204
|
-
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
|
-
});
|
|
235
|
-
}
|
|
236
|
-
const STANDALONE_FORMULA_SIZE_PT = 18;
|
|
237
|
-
const STANDALONE_FORMULA_MARGIN_PT = 72;
|
|
238
|
-
function odfToPdf(bytes, options) {
|
|
239
|
-
throwIfAborted(options?.signal);
|
|
240
|
-
const pkg = decodePackage$1(bytes);
|
|
241
|
-
const read = readOdfFormulaContent(pkg);
|
|
242
|
-
if (read.kind !== "formula") throw new Error("readOdfFormulaContent returned a non-formula ContentDocument");
|
|
243
|
-
const content = {
|
|
244
|
-
...read,
|
|
245
|
-
metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
|
|
246
|
-
};
|
|
247
|
-
const metrics = loadMathFont().metricsAt(STANDALONE_FORMULA_SIZE_PT);
|
|
248
|
-
const { box } = layoutFormula(content.formula.mathml, {
|
|
249
|
-
metrics,
|
|
250
|
-
sizePt: STANDALONE_FORMULA_SIZE_PT,
|
|
251
|
-
color: COLOR_BLACK
|
|
252
|
-
});
|
|
253
|
-
const flipped = flipY({
|
|
254
|
-
xPt: STANDALONE_FORMULA_MARGIN_PT,
|
|
255
|
-
yPt: STANDALONE_FORMULA_MARGIN_PT,
|
|
256
|
-
widthPt: box.widthPt,
|
|
257
|
-
heightPt: box.heightPt
|
|
258
|
-
}, PAGE_SIZE_A4.heightPt);
|
|
259
|
-
const layout = {
|
|
260
|
-
formatVersion: LAYOUT_FORMAT_VERSION,
|
|
261
|
-
metadata: content.metadata,
|
|
262
|
-
pages: [{
|
|
263
|
-
widthPt: PAGE_SIZE_A4.widthPt,
|
|
264
|
-
heightPt: PAGE_SIZE_A4.heightPt,
|
|
265
|
-
items: []
|
|
266
|
-
}],
|
|
267
|
-
images: {}
|
|
268
|
-
};
|
|
269
|
-
options?.onDocument?.({
|
|
270
|
-
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
271
|
-
content,
|
|
272
|
-
layout
|
|
273
|
-
});
|
|
274
|
-
throwIfAborted(options?.signal);
|
|
275
|
-
return writePdf(layout, {
|
|
276
|
-
signal: options?.signal,
|
|
277
|
-
formulas: [{
|
|
278
|
-
pageIndex: 0,
|
|
279
|
-
xPt: flipped.xPt,
|
|
280
|
-
yPt: flipped.yPt,
|
|
281
|
-
box
|
|
282
|
-
}]
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
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));
|
|
297
|
-
}
|
|
298
|
-
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));
|
|
310
|
-
}
|
|
311
|
-
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));
|
|
323
|
-
}
|
|
324
|
-
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));
|
|
336
|
-
}
|
|
337
|
-
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));
|
|
349
|
-
}
|
|
350
|
-
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));
|
|
362
|
-
}
|
|
363
|
-
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);
|
|
376
|
-
}
|
|
377
|
-
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 }));
|
|
388
|
-
}
|
|
389
|
-
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));
|
|
400
|
-
}
|
|
401
|
-
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));
|
|
412
|
-
}
|
|
413
|
-
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));
|
|
424
|
-
}
|
|
425
|
-
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));
|
|
436
|
-
}
|
|
437
|
-
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));
|
|
448
|
-
}
|
|
449
|
-
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 }));
|
|
463
|
-
}
|
|
464
|
-
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);
|
|
476
|
-
}
|
|
477
|
-
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));
|
|
491
|
-
}
|
|
492
|
-
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);
|
|
504
|
-
}
|
|
505
|
-
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));
|
|
516
|
-
}
|
|
517
|
-
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 }));
|
|
528
|
-
}
|
|
529
|
-
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));
|
|
541
|
-
}
|
|
542
|
-
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));
|
|
554
|
-
}
|
|
555
|
-
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
|
-
});
|
|
567
|
-
}
|
|
568
|
-
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
|
-
});
|
|
579
|
-
}
|
|
580
|
-
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
|
-
});
|
|
595
|
-
}
|
|
596
|
-
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
|
-
});
|
|
612
|
-
}
|
|
613
|
-
var OdmUnresolvedSectionError = class extends Error {
|
|
614
|
-
hrefs;
|
|
615
|
-
constructor(hrefs) {
|
|
616
|
-
super(`odmToPdf: ${hrefs.length} chapter section(s) could not be resolved -- no inline content and no resolveSubDocument result for: ${hrefs.join(", ")}`);
|
|
617
|
-
this.name = "OdmUnresolvedSectionError";
|
|
618
|
-
this.hrefs = hrefs;
|
|
619
|
-
}
|
|
620
|
-
};
|
|
621
|
-
const INLINE_SECTION_MARGIN_PT = 56.69291338582677;
|
|
622
|
-
const INLINE_SECTION_MARGINS = {
|
|
623
|
-
topPt: INLINE_SECTION_MARGIN_PT,
|
|
624
|
-
rightPt: INLINE_SECTION_MARGIN_PT,
|
|
625
|
-
bottomPt: INLINE_SECTION_MARGIN_PT,
|
|
626
|
-
leftPt: INLINE_SECTION_MARGIN_PT
|
|
627
|
-
};
|
|
628
|
-
function inlineOdmSectionToContentSection(section, pkg) {
|
|
629
|
-
const blocks = [];
|
|
630
|
-
for (const node of section.inlineContent ?? []) {
|
|
631
|
-
if (node.type !== "element") continue;
|
|
632
|
-
if (node.tag === "text:p" || node.tag === "text:h") blocks.push(readOdfParagraph(node, pkg));
|
|
633
|
-
else if (node.tag === "table:table") blocks.push(readOdfTable(node, pkg));
|
|
634
|
-
}
|
|
635
|
-
return {
|
|
636
|
-
pageSize: PAGE_SIZE_A4,
|
|
637
|
-
margins: INLINE_SECTION_MARGINS,
|
|
638
|
-
blocks
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
function withLeadingChapterBreak(section) {
|
|
642
|
-
const pageBreak = { kind: "pageBreak" };
|
|
643
|
-
return {
|
|
644
|
-
...section,
|
|
645
|
-
blocks: [pageBreak, ...section.blocks]
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
function odmToPdf(bytes, options) {
|
|
649
|
-
throwIfAborted(options?.signal);
|
|
650
|
-
const pkg = decodePackage$1(bytes);
|
|
651
|
-
const odm = readOdm(pkg);
|
|
652
|
-
const unresolvedHrefs = [];
|
|
653
|
-
const chapterSections = [];
|
|
654
|
-
const sourceFonts = extractSourceFonts({
|
|
655
|
-
kind: "odf",
|
|
656
|
-
package: pkg
|
|
657
|
-
});
|
|
658
|
-
for (const section of odm.sections) {
|
|
659
|
-
throwIfAborted(options?.signal);
|
|
660
|
-
if (section.inlineContent !== void 0) {
|
|
661
|
-
chapterSections.push([inlineOdmSectionToContentSection(section, pkg)]);
|
|
662
|
-
continue;
|
|
663
|
-
}
|
|
664
|
-
const chapterBytes = options?.resolveSubDocument?.(section.href);
|
|
665
|
-
if (chapterBytes === void 0) {
|
|
666
|
-
unresolvedHrefs.push(section.href);
|
|
667
|
-
continue;
|
|
668
|
-
}
|
|
669
|
-
const chapterPkg = decodePackage$1(chapterBytes);
|
|
670
|
-
sourceFonts.push(...extractSourceFonts({
|
|
671
|
-
kind: "odf",
|
|
672
|
-
package: chapterPkg
|
|
673
|
-
}));
|
|
674
|
-
const chapterContent = readOdtContent(chapterPkg);
|
|
675
|
-
if (chapterContent.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
|
|
676
|
-
chapterSections.push(chapterContent.sections);
|
|
677
|
-
}
|
|
678
|
-
if (unresolvedHrefs.length > 0) throw new OdmUnresolvedSectionError(unresolvedHrefs);
|
|
679
|
-
const combinedSections = [];
|
|
680
|
-
chapterSections.forEach((sections, chapterIndex) => {
|
|
681
|
-
if (chapterIndex === 0) {
|
|
682
|
-
combinedSections.push(...sections);
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
combinedSections.push(...sections.map((section, sectionIndex) => sectionIndex === 0 ? withLeadingChapterBreak(section) : section));
|
|
686
|
-
});
|
|
687
|
-
throwIfAborted(options?.signal);
|
|
688
|
-
const content = {
|
|
689
|
-
kind: "wordprocessing",
|
|
690
|
-
formatVersion: CONTENT_FORMAT_VERSION,
|
|
691
|
-
metadata: resolveMetadataTimestamps(readOdfMetadata(pkg), options?.clock),
|
|
692
|
-
sections: combinedSections
|
|
693
|
-
};
|
|
694
|
-
const fonts = createFontRegistry({
|
|
695
|
-
sourceFonts,
|
|
696
|
-
fonts: options?.fonts,
|
|
697
|
-
onSubstitution: options?.onFontSubstitution
|
|
698
|
-
});
|
|
699
|
-
const { document: layout, formulas } = convertWordprocessingToLayout(content, {
|
|
700
|
-
measurer: createFontMeasurer(fonts),
|
|
701
|
-
mathMetricsAt
|
|
702
|
-
});
|
|
703
|
-
return writePdf(layout, {
|
|
704
|
-
signal: options?.signal,
|
|
705
|
-
onSubstitution: options?.onSubstitution,
|
|
706
|
-
formulas,
|
|
707
|
-
fonts
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
function odbToXlsx(bytes, options) {
|
|
711
|
-
throwIfAborted(options?.signal);
|
|
712
|
-
const pkg = decodePackage$1(bytes);
|
|
713
|
-
const tables = readOdbTables(pkg, { timeZone: options?.timeZone });
|
|
714
|
-
throwIfAborted(options?.signal);
|
|
715
|
-
const content = odbTablesToSpreadsheetDocument(tables);
|
|
716
|
-
return encodePackage(buildXlsxPackage(content));
|
|
717
|
-
}
|
|
718
|
-
function odbToCsv(bytes, options) {
|
|
719
|
-
throwIfAborted(options?.signal);
|
|
720
|
-
const pkg = decodePackage$1(bytes);
|
|
721
|
-
const tables = readOdbTables(pkg, { timeZone: options?.timeZone });
|
|
722
|
-
throwIfAborted(options?.signal);
|
|
723
|
-
return buildOdbTableCsv(tables, options?.table);
|
|
724
|
-
}
|
|
725
|
-
function odbReportToDocx(content, options) {
|
|
726
|
-
throwIfAborted(options?.signal);
|
|
727
|
-
return encodePackage(buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
|
|
728
|
-
}
|
|
729
|
-
function odbReportToOdt(content, options) {
|
|
730
|
-
throwIfAborted(options?.signal);
|
|
731
|
-
return encodePackage$1(buildOdtPackage(content));
|
|
732
|
-
}
|
|
733
|
-
function odbReportToPdf(content, options) {
|
|
734
|
-
throwIfAborted(options?.signal);
|
|
735
|
-
if (content.kind !== "wordprocessing") throw new Error("odbReportToPdf requires a wordprocessing ContentDocument");
|
|
736
|
-
const fonts = createFontRegistry({
|
|
737
|
-
fonts: options?.fonts,
|
|
738
|
-
onSubstitution: options?.onFontSubstitution
|
|
739
|
-
});
|
|
740
|
-
const { document: layout, formulas } = convertWordprocessingToLayout(content, {
|
|
741
|
-
measurer: createFontMeasurer(fonts),
|
|
742
|
-
mathMetricsAt
|
|
743
|
-
});
|
|
744
|
-
options?.onDocument?.({
|
|
745
|
-
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
746
|
-
content,
|
|
747
|
-
layout
|
|
748
|
-
});
|
|
749
|
-
return writePdf(layout, {
|
|
750
|
-
signal: options?.signal,
|
|
751
|
-
onSubstitution: options?.onSubstitution,
|
|
752
|
-
formulas,
|
|
753
|
-
fonts
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
//#endregion
|
|
1
|
+
import { A as pdfToOdg, B as xlsxToOds, C as odsToXlsx, D as odtToPdf, E as odtToOdp, F as pdfToXlsx, I as pptxToDocx, L as pptxToOdp, M as pdfToOds, N as pdfToOdt, O as pdfToDocx, P as pdfToPptx, R as pptxToPdf, S as odsToPdf, T as odtToMarkdown, V as xlsxToPdf, _ as odgToPdf, a as docxToPptx, b as odpToPdf, c as markdownToOdt, d as odbReportToDocx, f as odbReportToOdt, g as odfToPdf, h as odbToXlsx, i as docxToPdf, j as pdfToOdp, k as pdfToMarkdown, l as markdownToPdf, m as odbToCsv, n as docxToMarkdown, o as inlineOdmSectionToContentSection, p as odbReportToPdf, r as docxToOdt, s as markdownToDocx, t as OdmUnresolvedSectionError, u as markdownToXlsx, v as odmToPdf, w as odtToDocx, x as odpToPptx, y as odpToOdt, z as xlsxToMarkdown } from "../convert-ULGgwmSb.js";
|
|
757
2
|
export { OdmUnresolvedSectionError, docxToMarkdown, docxToOdt, docxToPdf, docxToPptx, inlineOdmSectionToContentSection, markdownToDocx, markdownToOdt, markdownToPdf, markdownToXlsx, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odfToPdf, odgToPdf, odmToPdf, odpToOdt, odpToPdf, odpToPptx, odsToPdf, odsToXlsx, odtToDocx, odtToMarkdown, odtToOdp, odtToPdf, pdfToDocx, pdfToMarkdown, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pdfToXlsx, pptxToDocx, pptxToOdp, pptxToPdf, xlsxToMarkdown, xlsxToOds, xlsxToPdf };
|