js.documents 4.0.20 → 4.4.6

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 (116) hide show
  1. package/README.md +43 -29
  2. package/dist/cell-typing-CEWlywIc.d.cts +22 -0
  3. package/dist/cell-typing-CEWlywIc.d.ts +22 -0
  4. package/dist/codecs/read.cjs +66 -0
  5. package/dist/codecs/read.d.cts +15 -0
  6. package/dist/codecs/read.d.ts +15 -0
  7. package/dist/codecs/read.js +64 -0
  8. package/dist/codecs/registry.cjs +13 -59
  9. package/dist/codecs/registry.d.cts +2 -8
  10. package/dist/codecs/registry.d.ts +2 -8
  11. package/dist/codecs/registry.js +20 -64
  12. package/dist/convert/codec.cjs +11 -10
  13. package/dist/convert/codec.js +2 -1
  14. package/dist/convert/composition-to-pdf.cjs +133 -0
  15. package/dist/convert/composition-to-pdf.d.cts +7 -0
  16. package/dist/convert/composition-to-pdf.d.ts +7 -0
  17. package/dist/convert/composition-to-pdf.js +131 -0
  18. package/dist/convert/composition.cjs +31 -129
  19. package/dist/convert/composition.d.cts +14 -4
  20. package/dist/convert/composition.d.ts +14 -4
  21. package/dist/convert/composition.js +25 -128
  22. package/dist/convert/convert.cjs +35 -75
  23. package/dist/convert/convert.d.cts +5 -20
  24. package/dist/convert/convert.d.ts +5 -20
  25. package/dist/convert/convert.js +2 -32
  26. package/dist/convert/from-package.cjs +2 -1
  27. package/dist/convert/from-package.js +2 -1
  28. package/dist/convert/from-pdf.cjs +50 -0
  29. package/dist/convert/from-pdf.d.cts +26 -0
  30. package/dist/convert/from-pdf.d.ts +26 -0
  31. package/dist/convert/from-pdf.js +39 -0
  32. package/dist/convert/local.cjs +2 -1
  33. package/dist/convert/local.js +2 -1
  34. package/dist/convert/pdf-package-tables.cjs +76 -0
  35. package/dist/convert/pdf-package-tables.d.cts +6 -0
  36. package/dist/convert/pdf-package-tables.d.ts +6 -0
  37. package/dist/convert/pdf-package-tables.js +75 -0
  38. package/dist/csv/read.d.cts +1 -1
  39. package/dist/csv/read.d.ts +1 -1
  40. package/dist/diagnostics-DVAXKgcf.d.cts +10 -0
  41. package/dist/diagnostics-DVAXKgcf.d.ts +10 -0
  42. package/dist/edit/docx/content.cjs +1 -0
  43. package/dist/edit/docx/content.js +1 -0
  44. package/dist/edit/docx/paragraph.cjs +18 -1
  45. package/dist/edit/docx/paragraph.d.cts +3 -0
  46. package/dist/edit/docx/paragraph.d.ts +3 -0
  47. package/dist/edit/docx/paragraph.js +18 -1
  48. package/dist/edit/docx/props.cjs +1 -0
  49. package/dist/edit/docx/props.js +1 -0
  50. package/dist/edit/markdown/editor.cjs +1 -1
  51. package/dist/edit/markdown/editor.js +1 -1
  52. package/dist/edit/pdf/item.cjs +42 -1
  53. package/dist/edit/pdf/item.d.cts +2 -2
  54. package/dist/edit/pdf/item.d.ts +2 -2
  55. package/dist/edit/pdf/item.js +42 -2
  56. package/dist/edit/pdf/page.d.cts +1 -1
  57. package/dist/edit/pdf/page.d.ts +1 -1
  58. package/dist/fonts/registry.d.cts +1 -19
  59. package/dist/fonts/registry.d.ts +1 -19
  60. package/dist/hsqldb/binary-script.d.cts +1 -1
  61. package/dist/hsqldb/binary-script.d.ts +1 -1
  62. package/dist/hsqldb/cache.d.cts +1 -1
  63. package/dist/hsqldb/cache.d.ts +1 -1
  64. package/dist/hsqldb/rowformat.d.cts +1 -24
  65. package/dist/hsqldb/rowformat.d.ts +1 -24
  66. package/dist/index.cjs +17 -16
  67. package/dist/index.d.cts +11 -10
  68. package/dist/index.d.ts +11 -10
  69. package/dist/index.js +8 -7
  70. package/dist/{item-D9vQKT0T.d.cts → item-DhXpJNAQ.d.cts} +17 -3
  71. package/dist/{item-D9vQKT0T.d.ts → item-DhXpJNAQ.d.ts} +17 -3
  72. package/dist/layout/cell-typing.d.cts +1 -21
  73. package/dist/layout/cell-typing.d.ts +1 -21
  74. package/dist/layout/reconstruct.cjs +177 -14
  75. package/dist/layout/reconstruct.d.cts +1 -1
  76. package/dist/layout/reconstruct.d.ts +1 -1
  77. package/dist/layout/reconstruct.js +175 -12
  78. package/dist/layout/shared.cjs +2 -2
  79. package/dist/layout/shared.js +1 -1
  80. package/dist/markdown/math.cjs +5 -7
  81. package/dist/markdown/math.js +5 -7
  82. package/dist/markdown/read.cjs +15 -1
  83. package/dist/markdown/read.js +16 -2
  84. package/dist/markdown/write.cjs +7 -10
  85. package/dist/markdown/write.d.cts +3 -6
  86. package/dist/markdown/write.d.ts +3 -6
  87. package/dist/markdown/write.js +8 -11
  88. package/dist/metadata/write.cjs +2 -1
  89. package/dist/metadata/write.js +2 -1
  90. package/dist/model/bytes.cjs +8 -0
  91. package/dist/model/bytes.d.cts +2 -1
  92. package/dist/model/bytes.d.ts +2 -1
  93. package/dist/model/bytes.js +8 -1
  94. package/dist/odb/read.d.cts +1 -1
  95. package/dist/odb/read.d.ts +1 -1
  96. package/dist/odb/report/content.d.cts +1 -1
  97. package/dist/odb/report/content.d.ts +1 -1
  98. package/dist/odb/report/source.d.cts +1 -1
  99. package/dist/odb/report/source.d.ts +1 -1
  100. package/dist/odf/odt/read.cjs +1 -1
  101. package/dist/odf/odt/read.js +1 -1
  102. package/dist/registry-BcBT-bnX.d.cts +20 -0
  103. package/dist/registry-D1Pu5XxB.d.ts +20 -0
  104. package/dist/rowformat-Cl2exlEh.d.cts +25 -0
  105. package/dist/rowformat-Cl2exlEh.d.ts +25 -0
  106. package/dist/svg/diagnostics.d.cts +1 -9
  107. package/dist/svg/diagnostics.d.ts +1 -9
  108. package/dist/svg/read.d.cts +1 -1
  109. package/dist/svg/read.d.ts +1 -1
  110. package/dist/svg/write.d.cts +1 -1
  111. package/dist/svg/write.d.ts +1 -1
  112. package/package.json +27 -10
  113. package/dist/metadata/read.cjs +0 -15
  114. package/dist/metadata/read.d.cts +0 -9
  115. package/dist/metadata/read.d.ts +0 -9
  116. package/dist/metadata/read.js +0 -14
@@ -1,14 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_model_metadata = require("../model/metadata.cjs");
3
2
  const require_edit_docx_content = require("../edit/docx/content.cjs");
4
3
  const require_edit_pptx_content = require("../edit/pptx/content.cjs");
5
4
  const require_edit_odt_content = require("../edit/odt/content.cjs");
6
5
  const require_edit_odp_content = require("../edit/odp/content.cjs");
7
6
  const require_edit_ods_content = require("../edit/ods/content.cjs");
8
7
  const require_edit_odg_content = require("../edit/odg/content.cjs");
9
- const require_markdown_read = require("../markdown/read.cjs");
10
8
  const require_markdown_write = require("../markdown/write.cjs");
11
- const require_fonts_registry = require("../fonts/registry.cjs");
9
+ const require_markdown_read = require("../markdown/read.cjs");
12
10
  const require_ooxml_docx_read = require("../ooxml/docx/read.cjs");
13
11
  const require_ooxml_pptx_read = require("../ooxml/pptx/read.cjs");
14
12
  const require_odf_odt_read = require("../odf/odt/read.cjs");
@@ -22,21 +20,17 @@ const require_csv_write = require("../csv/write.cjs");
22
20
  const require_svg_text = require("../svg/text.cjs");
23
21
  const require_svg_read = require("../svg/read.cjs");
24
22
  const require_svg_write = require("../svg/write.cjs");
25
- const require_layout_engine = require("../layout/engine.cjs");
26
- const require_layout_slides = require("../layout/slides.cjs");
27
23
  const require_ports_abort = require("../ports/abort.cjs");
28
- const require_layout_sheets = require("../layout/sheets.cjs");
29
- const require_layout_drawing = require("../layout/drawing.cjs");
30
24
  const require_layout_reconstruct = require("../layout/reconstruct.cjs");
25
+ const require_convert_pdf_package_tables = require("./pdf-package-tables.cjs");
31
26
  const require_convert_variant_bridges = require("./variant-bridges.cjs");
32
27
  const require_convert_capability = require("./capability.cjs");
33
28
  let ooxml_js = require("ooxml.js");
34
29
  let document_schema_js = require("document-schema.js");
35
- let pdf_codec = require("pdf-codec");
36
30
  let odf_js = require("odf.js");
37
31
  require("markdown-codec");
32
+ let pdf_codec_read = require("pdf-codec/read");
38
33
  //#region src/convert/composition.ts
39
- const mathMetricsAt = (sizePt) => (0, pdf_codec.loadMathFont)().metricsAt(sizePt);
40
34
  const CONTENT_FORMATS = [
41
35
  "docx",
42
36
  "pptx",
@@ -184,12 +178,6 @@ const TRANSFORMS = {
184
178
  return require_convert_variant_bridges.presentationToDrawing(doc);
185
179
  }
186
180
  };
187
- const LAYOUT_ENGINES = {
188
- wordprocessing: require_layout_engine.convertWordprocessingToLayout,
189
- presentation: require_layout_slides.convertPresentationToLayout,
190
- spreadsheet: require_layout_sheets.convertSpreadsheetToLayout,
191
- drawing: require_layout_drawing.convertDrawingToLayout
192
- };
193
181
  const RECONSTRUCTORS = {
194
182
  wordprocessing: require_layout_reconstruct.reconstructWordprocessing,
195
183
  presentation: require_layout_reconstruct.reconstructPresentation,
@@ -228,110 +216,9 @@ function executeBridge(source, target, bytes, options) {
228
216
  options?.onDocument?.((0, document_schema_js.assemblePackage)(buildContent));
229
217
  return out;
230
218
  }
231
- function executeToPdf(format, bytes, options) {
232
- if (!LAYOUT_CAPABLE.has(format)) throw new Error(`executeToPdf: '${format}' has no layout engine of its own`);
233
- const node = FORMAT_NODES[format];
234
- let content;
235
- let fonts;
236
- if (isTextFormatNode(node)) {
237
- require_ports_abort.throwIfAborted(options?.signal);
238
- const text = node.decode(bytes);
239
- const read = node.read(text, options);
240
- content = {
241
- ...read,
242
- metadata: require_model_metadata.resolveMetadataTimestamps(read.metadata, options?.clock)
243
- };
244
- fonts = (0, pdf_codec.createFontRegistry)({
245
- fonts: options?.fonts,
246
- onSubstitution: options?.onFontSubstitution
247
- });
248
- } else {
249
- const pkg = node.decode(bytes);
250
- const read = node.read(pkg, options);
251
- content = {
252
- ...read,
253
- metadata: require_model_metadata.resolveMetadataTimestamps(read.metadata, options?.clock)
254
- };
255
- const fontSource = node.family === "odf" ? {
256
- kind: "odf",
257
- package: pkg
258
- } : format === "pptx" ? {
259
- kind: "pptx",
260
- package: pkg
261
- } : {
262
- kind: "docx",
263
- package: pkg
264
- };
265
- fonts = require_fonts_registry.createDocumentFontRegistry(fontSource, {
266
- fonts: options?.fonts,
267
- onFontSubstitution: options?.onFontSubstitution
268
- });
269
- }
270
- const measurer = (0, pdf_codec.createFontMeasurer)(fonts);
271
- let layout;
272
- let pages;
273
- let formulas;
274
- switch (content.kind) {
275
- case "wordprocessing": {
276
- const result = LAYOUT_ENGINES.wordprocessing(content, {
277
- measurer,
278
- mathMetricsAt
279
- });
280
- layout = result.document;
281
- pages = result.pages;
282
- formulas = result.formulas;
283
- break;
284
- }
285
- case "presentation": {
286
- const result = LAYOUT_ENGINES.presentation(content, {
287
- measurer,
288
- mathMetricsAt
289
- });
290
- layout = result.document;
291
- pages = result.pages;
292
- formulas = result.formulas;
293
- break;
294
- }
295
- case "spreadsheet": {
296
- const result = LAYOUT_ENGINES.spreadsheet(content, {
297
- measurer,
298
- mathMetricsAt,
299
- signal: options?.signal
300
- });
301
- layout = result.document;
302
- pages = result.pages;
303
- formulas = result.formulas;
304
- break;
305
- }
306
- case "drawing": {
307
- const result = LAYOUT_ENGINES.drawing(content, { measurer });
308
- layout = result.document;
309
- pages = result.pages;
310
- break;
311
- }
312
- default: throw new Error(`executeToPdf: cannot lay out a '${content.kind}' document`);
313
- }
314
- if (formulas === void 0) {
315
- const out = (0, pdf_codec.writePdf)(layout, {
316
- signal: options?.signal,
317
- onSubstitution: options?.onSubstitution,
318
- fonts
319
- });
320
- options?.onDocument?.((0, document_schema_js.assemblePackage)(content, pages));
321
- return out;
322
- }
323
- const out = (0, pdf_codec.writePdf)(layout, {
324
- signal: options?.signal,
325
- onSubstitution: options?.onSubstitution,
326
- formulas,
327
- fonts
328
- });
329
- options?.onDocument?.((0, document_schema_js.assemblePackage)(content, pages));
330
- return out;
331
- }
332
219
  function executeFromPdf(target, bytes, options) {
333
220
  const node = FORMAT_NODES[target];
334
- const layout = (0, pdf_codec.readPdf)(bytes, {
221
+ const layout = (0, pdf_codec_read.readPdf)(bytes, {
335
222
  signal: options?.signal,
336
223
  sink: options?.sink
337
224
  });
@@ -351,7 +238,9 @@ function executeFromPdf(target, bytes, options) {
351
238
  const pkg = node.build(content);
352
239
  out = node.encode(pkg);
353
240
  }
354
- options?.onDocument?.((0, document_schema_js.assemblePackage)(content, pages));
241
+ const reported = (0, document_schema_js.assemblePackage)(content, pages);
242
+ require_convert_pdf_package_tables.stampPdfPackageTables(reported, layout);
243
+ options?.onDocument?.(reported);
355
244
  return out;
356
245
  }
357
246
  function buildCompositionGraph() {
@@ -446,31 +335,44 @@ function resolveCompositionPlan(source, target) {
446
335
  function isContentFormat(format) {
447
336
  return format !== "pdf" && format !== "odf";
448
337
  }
449
- function convertDocument(source, target, bytes, options) {
450
- const plan = resolveCompositionPlan(source, target);
451
- if (plan === void 0) throw new require_convert_capability.UnsupportedConversionError(source, target);
338
+ function runCompositionPlan(plan, bytes, options, executors) {
452
339
  let current = bytes;
453
340
  for (let i = 0; i < plan.hops.length; i++) {
454
341
  const hop = plan.hops[i];
455
- if (hop === void 0) throw new Error("convertDocument: resolveCompositionPlan returned a malformed hop");
342
+ if (hop === void 0) throw new Error("runCompositionPlan: resolveCompositionPlan returned a malformed hop");
456
343
  const hopOptions = i === plan.hops.length - 1 ? options : options === void 0 ? void 0 : {
457
344
  ...options,
458
345
  onDocument: void 0
459
346
  };
460
347
  if (hop.executor === "toPdf") {
461
- if (!isContentFormat(hop.from)) throw new Error(`convertDocument: toPdf source '${hop.from}' is not a content format`);
462
- current = executeToPdf(hop.from, current, hopOptions);
348
+ if (!isContentFormat(hop.from)) throw new Error(`runCompositionPlan: toPdf source '${hop.from}' is not a content format`);
349
+ const toPdf = executors.toPdf;
350
+ if (toPdf === void 0) throw new Error(`runCompositionPlan: the plan's ${hop.from} -> ${hop.to} hop needs a toPdf executor, but this binding carries none (the read-only entry cannot render PDFs)`);
351
+ current = toPdf(hop.from, current, hopOptions);
463
352
  } else if (hop.executor === "fromPdf") {
464
- if (!isContentFormat(hop.to)) throw new Error(`convertDocument: fromPdf target '${hop.to}' is not a content format`);
465
- current = executeFromPdf(hop.to, current, hopOptions);
353
+ if (!isContentFormat(hop.to)) throw new Error(`runCompositionPlan: fromPdf target '${hop.to}' is not a content format`);
354
+ current = executors.fromPdf(hop.to, current, hopOptions);
466
355
  } else {
467
- if (!isContentFormat(hop.from) || !isContentFormat(hop.to)) throw new Error(`convertDocument: bridge endpoints '${hop.from}' -> '${hop.to}' are not both content formats`);
468
- current = executeBridge(hop.from, hop.to, current, hopOptions);
356
+ if (!isContentFormat(hop.from) || !isContentFormat(hop.to)) throw new Error(`runCompositionPlan: bridge endpoints '${hop.from}' -> '${hop.to}' are not both content formats`);
357
+ current = executors.bridge(hop.from, hop.to, current, hopOptions);
469
358
  }
470
359
  }
471
360
  return current;
472
361
  }
362
+ function convertDocumentFromPdf(target, bytes, options) {
363
+ const plan = resolveCompositionPlan("pdf", target);
364
+ if (plan === void 0) throw new require_convert_capability.UnsupportedConversionError("pdf", target);
365
+ return runCompositionPlan(plan, bytes, options, {
366
+ bridge: executeBridge,
367
+ fromPdf: executeFromPdf
368
+ });
369
+ }
473
370
  //#endregion
474
371
  exports.FORMAT_NODES = FORMAT_NODES;
475
- exports.convertDocument = convertDocument;
372
+ exports.LAYOUT_CAPABLE = LAYOUT_CAPABLE;
373
+ exports.convertDocumentFromPdf = convertDocumentFromPdf;
374
+ exports.executeBridge = executeBridge;
375
+ exports.executeFromPdf = executeFromPdf;
376
+ exports.isTextFormatNode = isTextFormatNode;
476
377
  exports.resolveCompositionPlan = resolveCompositionPlan;
378
+ exports.runCompositionPlan = runCompositionPlan;
@@ -1,8 +1,8 @@
1
1
  import { t as ClockPort } from "../clock-C7SUuYN0.cjs";
2
2
  import { DocumentFormat } from "./port.cjs";
3
3
  import { t as ContentVariant } from "../capability-an5gSNsu.cjs";
4
- import { SvgDiagnosticSink } from "../svg/diagnostics.cjs";
5
- import { CellTypeInferenceSink } from "../layout/cell-typing.cjs";
4
+ import { i as SvgDiagnosticSink } from "../diagnostics-DVAXKgcf.cjs";
5
+ import { i as CellTypeInferenceSink } from "../cell-typing-CEWlywIc.cjs";
6
6
  import { t as OmmlDiagnostic } from "../shared-DLZ3IQUl.cjs";
7
7
  import { ContentDocument, DocumentPackage, FontSubstitution, ProvidedFont } from "document-schema.js";
8
8
  import { PdfDiagnosticSink, WinAnsiSubstitution } from "pdf-codec";
@@ -51,7 +51,11 @@ interface TextFormatNode {
51
51
  readonly hasSourcePackage: false;
52
52
  }
53
53
  type FormatNode = PackageFormatNode | TextFormatNode;
54
+ declare function isTextFormatNode(node: FormatNode): node is TextFormatNode;
54
55
  declare const FORMAT_NODES: Readonly<Record<ContentFormat, FormatNode>>;
56
+ declare const LAYOUT_CAPABLE: ReadonlySet<ContentFormat>;
57
+ declare function executeBridge(source: ContentFormat, target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
58
+ declare function executeFromPdf(target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
55
59
  type HopExecutor = 'bridge' | 'toPdf' | 'fromPdf';
56
60
  interface CompositionHop {
57
61
  readonly executor: HopExecutor;
@@ -62,6 +66,12 @@ interface ConversionPlan {
62
66
  readonly hops: readonly CompositionHop[];
63
67
  }
64
68
  declare function resolveCompositionPlan(source: DocumentFormat, target: DocumentFormat): ConversionPlan | undefined;
65
- declare function convertDocument(source: DocumentFormat, target: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
69
+ interface CompositionExecutorBinding {
70
+ readonly bridge: (source: ContentFormat, target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => Uint8Array<ArrayBuffer>;
71
+ readonly fromPdf: (target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => Uint8Array<ArrayBuffer>;
72
+ readonly toPdf?: (source: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => Uint8Array<ArrayBuffer>;
73
+ }
74
+ declare function runCompositionPlan(plan: ConversionPlan, bytes: Uint8Array<ArrayBuffer>, options: UnifiedConversionOptions | undefined, executors: CompositionExecutorBinding): Uint8Array<ArrayBuffer>;
75
+ declare function convertDocumentFromPdf(target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
66
76
  //#endregion
67
- export { CompositionHop, ContentFormat, ConversionPlan, FORMAT_NODES, FormatNode, HopExecutor, UnifiedConversionOptions, convertDocument, resolveCompositionPlan };
77
+ export { CompositionExecutorBinding, CompositionHop, ContentFormat, ConversionPlan, FORMAT_NODES, FormatNode, HopExecutor, LAYOUT_CAPABLE, UnifiedConversionOptions, convertDocumentFromPdf, executeBridge, executeFromPdf, isTextFormatNode, resolveCompositionPlan, runCompositionPlan };
@@ -1,8 +1,8 @@
1
1
  import { t as ClockPort } from "../clock-C7SUuYN0.js";
2
2
  import { DocumentFormat } from "./port.js";
3
3
  import { t as ContentVariant } from "../capability-DX0lCSiI.js";
4
- import { SvgDiagnosticSink } from "../svg/diagnostics.js";
5
- import { CellTypeInferenceSink } from "../layout/cell-typing.js";
4
+ import { i as SvgDiagnosticSink } from "../diagnostics-DVAXKgcf.js";
5
+ import { i as CellTypeInferenceSink } from "../cell-typing-CEWlywIc.js";
6
6
  import { t as OmmlDiagnostic } from "../shared-DUOzjwcL.js";
7
7
  import { Package } from "ooxml.js";
8
8
  import { ContentDocument, DocumentPackage, FontSubstitution, ProvidedFont } from "document-schema.js";
@@ -51,7 +51,11 @@ interface TextFormatNode {
51
51
  readonly hasSourcePackage: false;
52
52
  }
53
53
  type FormatNode = PackageFormatNode | TextFormatNode;
54
+ declare function isTextFormatNode(node: FormatNode): node is TextFormatNode;
54
55
  declare const FORMAT_NODES: Readonly<Record<ContentFormat, FormatNode>>;
56
+ declare const LAYOUT_CAPABLE: ReadonlySet<ContentFormat>;
57
+ declare function executeBridge(source: ContentFormat, target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
58
+ declare function executeFromPdf(target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
55
59
  type HopExecutor = 'bridge' | 'toPdf' | 'fromPdf';
56
60
  interface CompositionHop {
57
61
  readonly executor: HopExecutor;
@@ -62,6 +66,12 @@ interface ConversionPlan {
62
66
  readonly hops: readonly CompositionHop[];
63
67
  }
64
68
  declare function resolveCompositionPlan(source: DocumentFormat, target: DocumentFormat): ConversionPlan | undefined;
65
- declare function convertDocument(source: DocumentFormat, target: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
69
+ interface CompositionExecutorBinding {
70
+ readonly bridge: (source: ContentFormat, target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => Uint8Array<ArrayBuffer>;
71
+ readonly fromPdf: (target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => Uint8Array<ArrayBuffer>;
72
+ readonly toPdf?: (source: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => Uint8Array<ArrayBuffer>;
73
+ }
74
+ declare function runCompositionPlan(plan: ConversionPlan, bytes: Uint8Array<ArrayBuffer>, options: UnifiedConversionOptions | undefined, executors: CompositionExecutorBinding): Uint8Array<ArrayBuffer>;
75
+ declare function convertDocumentFromPdf(target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
66
76
  //#endregion
67
- export { CompositionHop, ContentFormat, ConversionPlan, FORMAT_NODES, FormatNode, HopExecutor, UnifiedConversionOptions, convertDocument, resolveCompositionPlan };
77
+ export { CompositionExecutorBinding, CompositionHop, ContentFormat, ConversionPlan, FORMAT_NODES, FormatNode, HopExecutor, LAYOUT_CAPABLE, UnifiedConversionOptions, convertDocumentFromPdf, executeBridge, executeFromPdf, isTextFormatNode, resolveCompositionPlan, runCompositionPlan };
@@ -1,13 +1,11 @@
1
- import { resolveMetadataTimestamps } from "../model/metadata.js";
2
1
  import { buildDocxPackage } from "../edit/docx/content.js";
3
2
  import { buildPptxPackage } from "../edit/pptx/content.js";
4
3
  import { buildOdtPackage } from "../edit/odt/content.js";
5
4
  import { buildOdpPackage } from "../edit/odp/content.js";
6
5
  import { buildOdsPackage } from "../edit/ods/content.js";
7
6
  import { buildOdgPackage } from "../edit/odg/content.js";
8
- import { readMarkdownContent as readMarkdownContent$1 } from "../markdown/read.js";
9
7
  import { buildMarkdownText } from "../markdown/write.js";
10
- import { createDocumentFontRegistry } from "../fonts/registry.js";
8
+ import { readMarkdownContent as readMarkdownContent$1 } from "../markdown/read.js";
11
9
  import { readDocxContent as readDocxContent$1 } from "../ooxml/docx/read.js";
12
10
  import { readPptxContent as readPptxContent$1 } from "../ooxml/pptx/read.js";
13
11
  import { readOdtContent as readOdtContent$1 } from "../odf/odt/read.js";
@@ -21,21 +19,17 @@ import { buildCsvText } from "../csv/write.js";
21
19
  import { decodeSvgText, encodeSvgText } from "../svg/text.js";
22
20
  import { readSvgContent } from "../svg/read.js";
23
21
  import { buildSvgText } from "../svg/write.js";
24
- import { convertWordprocessingToLayout } from "../layout/engine.js";
25
- import { convertPresentationToLayout } from "../layout/slides.js";
26
22
  import { throwIfAborted } from "../ports/abort.js";
27
- import { convertSpreadsheetToLayout } from "../layout/sheets.js";
28
- import { convertDrawingToLayout } from "../layout/drawing.js";
29
23
  import { reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing } from "../layout/reconstruct.js";
24
+ import { stampPdfPackageTables } from "./pdf-package-tables.js";
30
25
  import { drawingToPresentation, presentationToDrawing, presentationToWordprocessing, wordprocessingToPresentation } from "./variant-bridges.js";
31
26
  import { UnsupportedConversionError } from "./capability.js";
32
27
  import { buildXlsxPackageFromContent, decodePackage, encodePackage, readXlsxContent } from "ooxml.js";
33
28
  import { assemblePackage } from "document-schema.js";
34
- import { createFontMeasurer, createFontRegistry, loadMathFont, readPdf, writePdf } from "pdf-codec";
35
29
  import { decodePackage as decodePackage$1, encodePackage as encodePackage$1 } from "odf.js";
36
30
  import "markdown-codec";
31
+ import { readPdf } from "pdf-codec/read";
37
32
  //#region src/convert/composition.ts
38
- const mathMetricsAt = (sizePt) => loadMathFont().metricsAt(sizePt);
39
33
  const CONTENT_FORMATS = [
40
34
  "docx",
41
35
  "pptx",
@@ -183,12 +177,6 @@ const TRANSFORMS = {
183
177
  return presentationToDrawing(doc);
184
178
  }
185
179
  };
186
- const LAYOUT_ENGINES = {
187
- wordprocessing: convertWordprocessingToLayout,
188
- presentation: convertPresentationToLayout,
189
- spreadsheet: convertSpreadsheetToLayout,
190
- drawing: convertDrawingToLayout
191
- };
192
180
  const RECONSTRUCTORS = {
193
181
  wordprocessing: reconstructWordprocessing,
194
182
  presentation: reconstructPresentation,
@@ -227,107 +215,6 @@ function executeBridge(source, target, bytes, options) {
227
215
  options?.onDocument?.(assemblePackage(buildContent));
228
216
  return out;
229
217
  }
230
- function executeToPdf(format, bytes, options) {
231
- if (!LAYOUT_CAPABLE.has(format)) throw new Error(`executeToPdf: '${format}' has no layout engine of its own`);
232
- const node = FORMAT_NODES[format];
233
- let content;
234
- let fonts;
235
- if (isTextFormatNode(node)) {
236
- throwIfAborted(options?.signal);
237
- const text = node.decode(bytes);
238
- const read = node.read(text, options);
239
- content = {
240
- ...read,
241
- metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
242
- };
243
- fonts = createFontRegistry({
244
- fonts: options?.fonts,
245
- onSubstitution: options?.onFontSubstitution
246
- });
247
- } else {
248
- const pkg = node.decode(bytes);
249
- const read = node.read(pkg, options);
250
- content = {
251
- ...read,
252
- metadata: resolveMetadataTimestamps(read.metadata, options?.clock)
253
- };
254
- const fontSource = node.family === "odf" ? {
255
- kind: "odf",
256
- package: pkg
257
- } : format === "pptx" ? {
258
- kind: "pptx",
259
- package: pkg
260
- } : {
261
- kind: "docx",
262
- package: pkg
263
- };
264
- fonts = createDocumentFontRegistry(fontSource, {
265
- fonts: options?.fonts,
266
- onFontSubstitution: options?.onFontSubstitution
267
- });
268
- }
269
- const measurer = createFontMeasurer(fonts);
270
- let layout;
271
- let pages;
272
- let formulas;
273
- switch (content.kind) {
274
- case "wordprocessing": {
275
- const result = LAYOUT_ENGINES.wordprocessing(content, {
276
- measurer,
277
- mathMetricsAt
278
- });
279
- layout = result.document;
280
- pages = result.pages;
281
- formulas = result.formulas;
282
- break;
283
- }
284
- case "presentation": {
285
- const result = LAYOUT_ENGINES.presentation(content, {
286
- measurer,
287
- mathMetricsAt
288
- });
289
- layout = result.document;
290
- pages = result.pages;
291
- formulas = result.formulas;
292
- break;
293
- }
294
- case "spreadsheet": {
295
- const result = LAYOUT_ENGINES.spreadsheet(content, {
296
- measurer,
297
- mathMetricsAt,
298
- signal: options?.signal
299
- });
300
- layout = result.document;
301
- pages = result.pages;
302
- formulas = result.formulas;
303
- break;
304
- }
305
- case "drawing": {
306
- const result = LAYOUT_ENGINES.drawing(content, { measurer });
307
- layout = result.document;
308
- pages = result.pages;
309
- break;
310
- }
311
- default: throw new Error(`executeToPdf: cannot lay out a '${content.kind}' document`);
312
- }
313
- if (formulas === void 0) {
314
- const out = writePdf(layout, {
315
- signal: options?.signal,
316
- onSubstitution: options?.onSubstitution,
317
- fonts
318
- });
319
- options?.onDocument?.(assemblePackage(content, pages));
320
- return out;
321
- }
322
- const out = writePdf(layout, {
323
- signal: options?.signal,
324
- onSubstitution: options?.onSubstitution,
325
- formulas,
326
- fonts
327
- });
328
- options?.onDocument?.(assemblePackage(content, pages));
329
- return out;
330
- }
331
218
  function executeFromPdf(target, bytes, options) {
332
219
  const node = FORMAT_NODES[target];
333
220
  const layout = readPdf(bytes, {
@@ -350,7 +237,9 @@ function executeFromPdf(target, bytes, options) {
350
237
  const pkg = node.build(content);
351
238
  out = node.encode(pkg);
352
239
  }
353
- options?.onDocument?.(assemblePackage(content, pages));
240
+ const reported = assemblePackage(content, pages);
241
+ stampPdfPackageTables(reported, layout);
242
+ options?.onDocument?.(reported);
354
243
  return out;
355
244
  }
356
245
  function buildCompositionGraph() {
@@ -445,29 +334,37 @@ function resolveCompositionPlan(source, target) {
445
334
  function isContentFormat(format) {
446
335
  return format !== "pdf" && format !== "odf";
447
336
  }
448
- function convertDocument(source, target, bytes, options) {
449
- const plan = resolveCompositionPlan(source, target);
450
- if (plan === void 0) throw new UnsupportedConversionError(source, target);
337
+ function runCompositionPlan(plan, bytes, options, executors) {
451
338
  let current = bytes;
452
339
  for (let i = 0; i < plan.hops.length; i++) {
453
340
  const hop = plan.hops[i];
454
- if (hop === void 0) throw new Error("convertDocument: resolveCompositionPlan returned a malformed hop");
341
+ if (hop === void 0) throw new Error("runCompositionPlan: resolveCompositionPlan returned a malformed hop");
455
342
  const hopOptions = i === plan.hops.length - 1 ? options : options === void 0 ? void 0 : {
456
343
  ...options,
457
344
  onDocument: void 0
458
345
  };
459
346
  if (hop.executor === "toPdf") {
460
- if (!isContentFormat(hop.from)) throw new Error(`convertDocument: toPdf source '${hop.from}' is not a content format`);
461
- current = executeToPdf(hop.from, current, hopOptions);
347
+ if (!isContentFormat(hop.from)) throw new Error(`runCompositionPlan: toPdf source '${hop.from}' is not a content format`);
348
+ const toPdf = executors.toPdf;
349
+ if (toPdf === void 0) throw new Error(`runCompositionPlan: the plan's ${hop.from} -> ${hop.to} hop needs a toPdf executor, but this binding carries none (the read-only entry cannot render PDFs)`);
350
+ current = toPdf(hop.from, current, hopOptions);
462
351
  } else if (hop.executor === "fromPdf") {
463
- if (!isContentFormat(hop.to)) throw new Error(`convertDocument: fromPdf target '${hop.to}' is not a content format`);
464
- current = executeFromPdf(hop.to, current, hopOptions);
352
+ if (!isContentFormat(hop.to)) throw new Error(`runCompositionPlan: fromPdf target '${hop.to}' is not a content format`);
353
+ current = executors.fromPdf(hop.to, current, hopOptions);
465
354
  } else {
466
- if (!isContentFormat(hop.from) || !isContentFormat(hop.to)) throw new Error(`convertDocument: bridge endpoints '${hop.from}' -> '${hop.to}' are not both content formats`);
467
- current = executeBridge(hop.from, hop.to, current, hopOptions);
355
+ if (!isContentFormat(hop.from) || !isContentFormat(hop.to)) throw new Error(`runCompositionPlan: bridge endpoints '${hop.from}' -> '${hop.to}' are not both content formats`);
356
+ current = executors.bridge(hop.from, hop.to, current, hopOptions);
468
357
  }
469
358
  }
470
359
  return current;
471
360
  }
361
+ function convertDocumentFromPdf(target, bytes, options) {
362
+ const plan = resolveCompositionPlan("pdf", target);
363
+ if (plan === void 0) throw new UnsupportedConversionError("pdf", target);
364
+ return runCompositionPlan(plan, bytes, options, {
365
+ bridge: executeBridge,
366
+ fromPdf: executeFromPdf
367
+ });
368
+ }
472
369
  //#endregion
473
- export { FORMAT_NODES, convertDocument, resolveCompositionPlan };
370
+ export { FORMAT_NODES, LAYOUT_CAPABLE, convertDocumentFromPdf, executeBridge, executeFromPdf, isTextFormatNode, resolveCompositionPlan, runCompositionPlan };