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