documents.js 1.97.11 → 1.98.1
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
|
@@ -1,2 +1,412 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveMetadataTimestamps } from "../model/metadata.js";
|
|
2
|
+
import { buildDocxPackage } from "../edit/docx/content.js";
|
|
3
|
+
import { buildPptxPackage } from "../edit/pptx/content.js";
|
|
4
|
+
import { buildOdtPackage } from "../edit/odt/content.js";
|
|
5
|
+
import { buildOdpPackage } from "../edit/odp/content.js";
|
|
6
|
+
import { buildOdsPackage } from "../edit/ods/content.js";
|
|
7
|
+
import { buildOdgPackage } from "../edit/odg/content.js";
|
|
8
|
+
import { readMarkdownContent } from "../markdown/read.js";
|
|
9
|
+
import { buildMarkdownText } from "../markdown/write.js";
|
|
10
|
+
import { createDocumentFontRegistry } from "../fonts/registry.js";
|
|
11
|
+
import { readDocxContent } from "../ooxml/docx/read.js";
|
|
12
|
+
import { readPptxContent } from "../ooxml/pptx/read.js";
|
|
13
|
+
import { readOdtContent } from "../odf/odt/read.js";
|
|
14
|
+
import { readOdpContent } from "../odf/odp/read.js";
|
|
15
|
+
import { readOdsContent } from "../odf/ods/read.js";
|
|
16
|
+
import { readOdgContent } from "../odf/odg/read.js";
|
|
17
|
+
import { decodeMarkdownText, encodeMarkdownText } from "../markdown/text.js";
|
|
18
|
+
import { convertWordprocessingToLayout } from "../layout/engine.js";
|
|
19
|
+
import { convertPresentationToLayout } from "../layout/slides.js";
|
|
20
|
+
import { throwIfAborted } from "../ports/abort.js";
|
|
21
|
+
import { convertSpreadsheetToLayout } from "../layout/sheets.js";
|
|
22
|
+
import { convertDrawingToLayout } from "../layout/drawing.js";
|
|
23
|
+
import { reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing } from "../layout/reconstruct.js";
|
|
24
|
+
import { presentationToWordprocessing, wordprocessingToPresentation } from "./variant-bridges.js";
|
|
25
|
+
import { UnsupportedConversionError } from "./capability.js";
|
|
26
|
+
import { buildXlsxPackage, decodePackage, encodePackage, readXlsxContent } from "ooxml.js";
|
|
27
|
+
import { DOCUMENT_PACKAGE_FORMAT_VERSION } from "document-schema.js";
|
|
28
|
+
import { decodePackage as decodePackage$1, encodePackage as encodePackage$1 } from "odf.js";
|
|
29
|
+
import "markdown-codec";
|
|
30
|
+
import { createFontMeasurer, createFontRegistry, loadMathFont, readPdf, writePdf } from "pdf-codec";
|
|
31
|
+
//#region src/convert/composition.ts
|
|
32
|
+
const mathMetricsAt = (sizePt) => loadMathFont().metricsAt(sizePt);
|
|
33
|
+
const CONTENT_FORMATS = [
|
|
34
|
+
"docx",
|
|
35
|
+
"pptx",
|
|
36
|
+
"xlsx",
|
|
37
|
+
"odt",
|
|
38
|
+
"odp",
|
|
39
|
+
"ods",
|
|
40
|
+
"odg",
|
|
41
|
+
"markdown"
|
|
42
|
+
];
|
|
43
|
+
const FORMAT_NODES = {
|
|
44
|
+
docx: {
|
|
45
|
+
variant: "wordprocessing",
|
|
46
|
+
family: "ooxml",
|
|
47
|
+
decode: (bytes) => decodePackage(bytes),
|
|
48
|
+
read: (pkg, options) => readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic }),
|
|
49
|
+
build: (content, options) => buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }),
|
|
50
|
+
encode: (pkg) => encodePackage(pkg),
|
|
51
|
+
hasSourcePackage: true
|
|
52
|
+
},
|
|
53
|
+
pptx: {
|
|
54
|
+
variant: "presentation",
|
|
55
|
+
family: "ooxml",
|
|
56
|
+
decode: (bytes) => decodePackage(bytes),
|
|
57
|
+
read: (pkg) => readPptxContent(pkg),
|
|
58
|
+
build: (content) => buildPptxPackage(content),
|
|
59
|
+
encode: (pkg) => encodePackage(pkg),
|
|
60
|
+
hasSourcePackage: true
|
|
61
|
+
},
|
|
62
|
+
xlsx: {
|
|
63
|
+
variant: "spreadsheet",
|
|
64
|
+
family: "ooxml",
|
|
65
|
+
decode: (bytes) => decodePackage(bytes),
|
|
66
|
+
read: (pkg) => readXlsxContent(pkg),
|
|
67
|
+
build: (content) => buildXlsxPackage(content),
|
|
68
|
+
encode: (pkg) => encodePackage(pkg),
|
|
69
|
+
hasSourcePackage: true
|
|
70
|
+
},
|
|
71
|
+
odt: {
|
|
72
|
+
variant: "wordprocessing",
|
|
73
|
+
family: "odf",
|
|
74
|
+
decode: (bytes) => decodePackage$1(bytes),
|
|
75
|
+
read: (pkg) => readOdtContent(pkg),
|
|
76
|
+
build: (content) => buildOdtPackage(content),
|
|
77
|
+
encode: (pkg) => encodePackage$1(pkg),
|
|
78
|
+
hasSourcePackage: true
|
|
79
|
+
},
|
|
80
|
+
odp: {
|
|
81
|
+
variant: "presentation",
|
|
82
|
+
family: "odf",
|
|
83
|
+
decode: (bytes) => decodePackage$1(bytes),
|
|
84
|
+
read: (pkg) => readOdpContent(pkg),
|
|
85
|
+
build: (content) => buildOdpPackage(content),
|
|
86
|
+
encode: (pkg) => encodePackage$1(pkg),
|
|
87
|
+
hasSourcePackage: true
|
|
88
|
+
},
|
|
89
|
+
ods: {
|
|
90
|
+
variant: "spreadsheet",
|
|
91
|
+
family: "odf",
|
|
92
|
+
decode: (bytes) => decodePackage$1(bytes),
|
|
93
|
+
read: (pkg) => readOdsContent(pkg),
|
|
94
|
+
build: (content) => buildOdsPackage(content),
|
|
95
|
+
encode: (pkg) => encodePackage$1(pkg),
|
|
96
|
+
hasSourcePackage: true
|
|
97
|
+
},
|
|
98
|
+
odg: {
|
|
99
|
+
variant: "drawing",
|
|
100
|
+
family: "odf",
|
|
101
|
+
decode: (bytes) => decodePackage$1(bytes),
|
|
102
|
+
read: (pkg) => readOdgContent(pkg),
|
|
103
|
+
build: (content) => buildOdgPackage(content),
|
|
104
|
+
encode: (pkg) => encodePackage$1(pkg),
|
|
105
|
+
hasSourcePackage: true
|
|
106
|
+
},
|
|
107
|
+
markdown: {
|
|
108
|
+
variant: "wordprocessing",
|
|
109
|
+
family: "markdown",
|
|
110
|
+
decode: (bytes) => decodeMarkdownText(bytes),
|
|
111
|
+
read: (text, options) => readMarkdownContent(text, {
|
|
112
|
+
signal: options?.signal,
|
|
113
|
+
images: options?.images
|
|
114
|
+
}),
|
|
115
|
+
build: (content) => buildMarkdownText(content),
|
|
116
|
+
encode: (text) => encodeMarkdownText(text),
|
|
117
|
+
hasSourcePackage: false
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const LAYOUT_CAPABLE = /* @__PURE__ */ new Set([
|
|
121
|
+
"docx",
|
|
122
|
+
"pptx",
|
|
123
|
+
"odt",
|
|
124
|
+
"odp",
|
|
125
|
+
"ods",
|
|
126
|
+
"odg",
|
|
127
|
+
"markdown"
|
|
128
|
+
]);
|
|
129
|
+
const TRANSFORMS = {
|
|
130
|
+
"wordprocessing->presentation": (doc) => {
|
|
131
|
+
if (doc.kind !== "wordprocessing") throw new Error("wordprocessingToPresentation: expected a wordprocessing ContentDocument");
|
|
132
|
+
return wordprocessingToPresentation(doc);
|
|
133
|
+
},
|
|
134
|
+
"presentation->wordprocessing": (doc) => {
|
|
135
|
+
if (doc.kind !== "presentation") throw new Error("presentationToWordprocessing: expected a presentation ContentDocument");
|
|
136
|
+
return presentationToWordprocessing(doc);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const LAYOUT_ENGINES = {
|
|
140
|
+
wordprocessing: convertWordprocessingToLayout,
|
|
141
|
+
presentation: convertPresentationToLayout,
|
|
142
|
+
spreadsheet: convertSpreadsheetToLayout,
|
|
143
|
+
drawing: convertDrawingToLayout
|
|
144
|
+
};
|
|
145
|
+
const RECONSTRUCTORS = {
|
|
146
|
+
wordprocessing: reconstructWordprocessing,
|
|
147
|
+
presentation: reconstructPresentation,
|
|
148
|
+
drawing: reconstructDrawing,
|
|
149
|
+
spreadsheet: reconstructSpreadsheet
|
|
150
|
+
};
|
|
151
|
+
function executeBridge(source, target, bytes, options) {
|
|
152
|
+
throwIfAborted(options?.signal);
|
|
153
|
+
const sourceNode = FORMAT_NODES[source];
|
|
154
|
+
const targetNode = FORMAT_NODES[target];
|
|
155
|
+
let content;
|
|
156
|
+
if (sourceNode.family === "markdown") {
|
|
157
|
+
const text = sourceNode.decode(bytes);
|
|
158
|
+
content = sourceNode.read(text, options);
|
|
159
|
+
} else {
|
|
160
|
+
const pkg = sourceNode.decode(bytes);
|
|
161
|
+
content = sourceNode.read(pkg, options);
|
|
162
|
+
}
|
|
163
|
+
if (content.kind !== sourceNode.variant) throw new Error(`executeBridge: ${source} read returned a non-${sourceNode.variant} ContentDocument`);
|
|
164
|
+
let buildContent = content;
|
|
165
|
+
if (sourceNode.variant !== targetNode.variant) {
|
|
166
|
+
const key = `${sourceNode.variant}->${targetNode.variant}`;
|
|
167
|
+
const transform = TRANSFORMS[key];
|
|
168
|
+
if (transform === void 0) throw new Error(`executeBridge: no transform registered for ${key}`);
|
|
169
|
+
buildContent = transform(content);
|
|
170
|
+
}
|
|
171
|
+
throwIfAborted(options?.signal);
|
|
172
|
+
options?.onDocument?.({
|
|
173
|
+
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
174
|
+
content: buildContent
|
|
175
|
+
});
|
|
176
|
+
if (targetNode.family === "markdown") {
|
|
177
|
+
const text = targetNode.build(buildContent);
|
|
178
|
+
return targetNode.encode(text);
|
|
179
|
+
}
|
|
180
|
+
const pkg = targetNode.build(buildContent, options);
|
|
181
|
+
return targetNode.encode(pkg);
|
|
182
|
+
}
|
|
183
|
+
function executeToPdf(format, bytes, options) {
|
|
184
|
+
if (!LAYOUT_CAPABLE.has(format)) throw new Error(`executeToPdf: '${format}' has no layout engine of its own`);
|
|
185
|
+
const node = FORMAT_NODES[format];
|
|
186
|
+
let content;
|
|
187
|
+
let fonts;
|
|
188
|
+
if (node.family === "markdown") {
|
|
189
|
+
throwIfAborted(options?.signal);
|
|
190
|
+
const text = node.decode(bytes);
|
|
191
|
+
const read = node.read(text, options);
|
|
192
|
+
content = {
|
|
193
|
+
...read,
|
|
194
|
+
metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
|
|
195
|
+
};
|
|
196
|
+
fonts = createFontRegistry({
|
|
197
|
+
fonts: options?.fonts,
|
|
198
|
+
onSubstitution: options?.onFontSubstitution
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
const pkg = node.decode(bytes);
|
|
202
|
+
const read = node.read(pkg, options);
|
|
203
|
+
content = {
|
|
204
|
+
...read,
|
|
205
|
+
metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
|
|
206
|
+
};
|
|
207
|
+
const fontSource = node.family === "odf" ? {
|
|
208
|
+
kind: "odf",
|
|
209
|
+
package: pkg
|
|
210
|
+
} : format === "pptx" ? {
|
|
211
|
+
kind: "pptx",
|
|
212
|
+
package: pkg
|
|
213
|
+
} : {
|
|
214
|
+
kind: "docx",
|
|
215
|
+
package: pkg
|
|
216
|
+
};
|
|
217
|
+
fonts = createDocumentFontRegistry(fontSource, {
|
|
218
|
+
fonts: options?.fonts,
|
|
219
|
+
onFontSubstitution: options?.onFontSubstitution
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
const measurer = createFontMeasurer(fonts);
|
|
223
|
+
let layout;
|
|
224
|
+
let formulas;
|
|
225
|
+
switch (content.kind) {
|
|
226
|
+
case "wordprocessing": {
|
|
227
|
+
const result = LAYOUT_ENGINES.wordprocessing(content, {
|
|
228
|
+
measurer,
|
|
229
|
+
mathMetricsAt
|
|
230
|
+
});
|
|
231
|
+
layout = result.document;
|
|
232
|
+
formulas = result.formulas;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
case "presentation": {
|
|
236
|
+
const result = LAYOUT_ENGINES.presentation(content, {
|
|
237
|
+
measurer,
|
|
238
|
+
mathMetricsAt
|
|
239
|
+
});
|
|
240
|
+
layout = result.document;
|
|
241
|
+
formulas = result.formulas;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case "spreadsheet": {
|
|
245
|
+
const result = LAYOUT_ENGINES.spreadsheet(content, {
|
|
246
|
+
measurer,
|
|
247
|
+
mathMetricsAt,
|
|
248
|
+
signal: options?.signal
|
|
249
|
+
});
|
|
250
|
+
layout = result.document;
|
|
251
|
+
formulas = result.formulas;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case "drawing":
|
|
255
|
+
layout = LAYOUT_ENGINES.drawing(content, { measurer });
|
|
256
|
+
break;
|
|
257
|
+
default: throw new Error(`executeToPdf: cannot lay out a '${content.kind}' document`);
|
|
258
|
+
}
|
|
259
|
+
options?.onDocument?.({
|
|
260
|
+
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
261
|
+
content,
|
|
262
|
+
layout
|
|
263
|
+
});
|
|
264
|
+
if (formulas === void 0) return writePdf(layout, {
|
|
265
|
+
signal: options?.signal,
|
|
266
|
+
onSubstitution: options?.onSubstitution,
|
|
267
|
+
fonts
|
|
268
|
+
});
|
|
269
|
+
return writePdf(layout, {
|
|
270
|
+
signal: options?.signal,
|
|
271
|
+
onSubstitution: options?.onSubstitution,
|
|
272
|
+
formulas,
|
|
273
|
+
fonts
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function executeFromPdf(target, bytes, options) {
|
|
277
|
+
const node = FORMAT_NODES[target];
|
|
278
|
+
const layout = readPdf(bytes, {
|
|
279
|
+
signal: options?.signal,
|
|
280
|
+
sink: options?.sink
|
|
281
|
+
});
|
|
282
|
+
const content = RECONSTRUCTORS[node.variant](layout, { signal: options?.signal });
|
|
283
|
+
options?.onDocument?.({
|
|
284
|
+
formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
|
|
285
|
+
content,
|
|
286
|
+
layout
|
|
287
|
+
});
|
|
288
|
+
if (node.family === "markdown") {
|
|
289
|
+
const text = node.build(content);
|
|
290
|
+
return node.encode(text);
|
|
291
|
+
}
|
|
292
|
+
const pkg = node.build(content);
|
|
293
|
+
return node.encode(pkg);
|
|
294
|
+
}
|
|
295
|
+
function buildCompositionGraph() {
|
|
296
|
+
const adj = /* @__PURE__ */ new Map();
|
|
297
|
+
const addDirected = (from, to, cost) => {
|
|
298
|
+
const list = adj.get(from);
|
|
299
|
+
if (list === void 0) adj.set(from, [{
|
|
300
|
+
to,
|
|
301
|
+
cost
|
|
302
|
+
}]);
|
|
303
|
+
else list.push({
|
|
304
|
+
to,
|
|
305
|
+
cost
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
const addEdge = (from, to, cost) => {
|
|
309
|
+
addDirected(from, to, cost);
|
|
310
|
+
addDirected(to, from, cost);
|
|
311
|
+
};
|
|
312
|
+
for (const a of CONTENT_FORMATS) for (const b of CONTENT_FORMATS) {
|
|
313
|
+
if (a === b) continue;
|
|
314
|
+
if (FORMAT_NODES[a].variant === FORMAT_NODES[b].variant) addEdge(a, b, 1);
|
|
315
|
+
}
|
|
316
|
+
for (const key of Object.keys(TRANSFORMS)) {
|
|
317
|
+
const parts = key.split("->");
|
|
318
|
+
const fromVariant = parts[0];
|
|
319
|
+
const toVariant = parts[1];
|
|
320
|
+
if (fromVariant === void 0 || toVariant === void 0) continue;
|
|
321
|
+
for (const a of CONTENT_FORMATS) {
|
|
322
|
+
if (FORMAT_NODES[a].variant !== fromVariant) continue;
|
|
323
|
+
for (const b of CONTENT_FORMATS) {
|
|
324
|
+
if (FORMAT_NODES[b].variant !== toVariant) continue;
|
|
325
|
+
addEdge(a, b, 2);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
for (const format of CONTENT_FORMATS) if (LAYOUT_CAPABLE.has(format)) addEdge(format, "pdf", 3);
|
|
330
|
+
return adj;
|
|
331
|
+
}
|
|
332
|
+
const COMPOSITION_GRAPH = buildCompositionGraph();
|
|
333
|
+
function shortestPath(source, target) {
|
|
334
|
+
if (source === target) return;
|
|
335
|
+
const distances = /* @__PURE__ */ new Map([[source, 0]]);
|
|
336
|
+
const previous = /* @__PURE__ */ new Map();
|
|
337
|
+
const visited = /* @__PURE__ */ new Set();
|
|
338
|
+
while (true) {
|
|
339
|
+
let current = void 0;
|
|
340
|
+
let currentDist = Infinity;
|
|
341
|
+
for (const [node, dist] of distances) if (!visited.has(node) && dist < currentDist) {
|
|
342
|
+
current = node;
|
|
343
|
+
currentDist = dist;
|
|
344
|
+
}
|
|
345
|
+
if (current === void 0 || current === target) break;
|
|
346
|
+
visited.add(current);
|
|
347
|
+
for (const edge of COMPOSITION_GRAPH.get(current) ?? []) {
|
|
348
|
+
if (visited.has(edge.to)) continue;
|
|
349
|
+
const alt = currentDist + edge.cost;
|
|
350
|
+
const known = distances.get(edge.to);
|
|
351
|
+
if (known === void 0 || alt < known) {
|
|
352
|
+
distances.set(edge.to, alt);
|
|
353
|
+
previous.set(edge.to, current);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (distances.get(target) === void 0) return;
|
|
358
|
+
const path = [];
|
|
359
|
+
let cursor = target;
|
|
360
|
+
while (cursor !== void 0) {
|
|
361
|
+
path.unshift(cursor);
|
|
362
|
+
cursor = previous.get(cursor);
|
|
363
|
+
}
|
|
364
|
+
return path;
|
|
365
|
+
}
|
|
366
|
+
function resolveCompositionPlan(source, target) {
|
|
367
|
+
const path = shortestPath(source, target);
|
|
368
|
+
if (path === void 0) return;
|
|
369
|
+
if (path.length > 4) return;
|
|
370
|
+
const hops = [];
|
|
371
|
+
for (let i = 0; i + 1 < path.length; i++) {
|
|
372
|
+
const from = path[i];
|
|
373
|
+
const to = path[i + 1];
|
|
374
|
+
if (from === void 0 || to === void 0) return;
|
|
375
|
+
const executor = to === "pdf" ? "toPdf" : from === "pdf" ? "fromPdf" : "bridge";
|
|
376
|
+
hops.push({
|
|
377
|
+
executor,
|
|
378
|
+
from,
|
|
379
|
+
to
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
return { hops };
|
|
383
|
+
}
|
|
384
|
+
function isContentFormat(format) {
|
|
385
|
+
return format !== "pdf" && format !== "odf";
|
|
386
|
+
}
|
|
387
|
+
function convertDocument(source, target, bytes, options) {
|
|
388
|
+
const plan = resolveCompositionPlan(source, target);
|
|
389
|
+
if (plan === void 0) throw new UnsupportedConversionError(source, target);
|
|
390
|
+
let current = bytes;
|
|
391
|
+
for (let i = 0; i < plan.hops.length; i++) {
|
|
392
|
+
const hop = plan.hops[i];
|
|
393
|
+
if (hop === void 0) throw new Error("convertDocument: resolveCompositionPlan returned a malformed hop");
|
|
394
|
+
const hopOptions = i === plan.hops.length - 1 ? options : options === void 0 ? void 0 : {
|
|
395
|
+
...options,
|
|
396
|
+
onDocument: void 0
|
|
397
|
+
};
|
|
398
|
+
if (hop.executor === "toPdf") {
|
|
399
|
+
if (!isContentFormat(hop.from)) throw new Error(`convertDocument: toPdf source '${hop.from}' is not a content format`);
|
|
400
|
+
current = executeToPdf(hop.from, current, hopOptions);
|
|
401
|
+
} else if (hop.executor === "fromPdf") {
|
|
402
|
+
if (!isContentFormat(hop.to)) throw new Error(`convertDocument: fromPdf target '${hop.to}' is not a content format`);
|
|
403
|
+
current = executeFromPdf(hop.to, current, hopOptions);
|
|
404
|
+
} else {
|
|
405
|
+
if (!isContentFormat(hop.from) || !isContentFormat(hop.to)) throw new Error(`convertDocument: bridge endpoints '${hop.from}' -> '${hop.to}' are not both content formats`);
|
|
406
|
+
current = executeBridge(hop.from, hop.to, current, hopOptions);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return current;
|
|
410
|
+
}
|
|
411
|
+
//#endregion
|
|
2
412
|
export { FORMAT_NODES, convertDocument, resolveCompositionPlan };
|