js.documents 14.4.56 → 14.4.57

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 (163) hide show
  1. package/dist/codecs/read.cjs +2 -2
  2. package/dist/codecs/read.js +1 -1
  3. package/dist/composition-plan-CfvhXeOC.cjs +627 -0
  4. package/dist/composition-plan-DU9nPPN7.d.cts +102 -0
  5. package/dist/composition-plan-f0zaExUW.js +508 -0
  6. package/dist/composition-plan-l6QPO4FX.d.ts +102 -0
  7. package/dist/convert/composition-plan.cjs +7 -0
  8. package/dist/convert/composition-plan.d.cts +2 -0
  9. package/dist/convert/composition-plan.d.ts +2 -0
  10. package/dist/convert/composition-plan.js +2 -0
  11. package/dist/convert/composition-to-pdf.cjs +12 -12
  12. package/dist/convert/composition-to-pdf.d.cts +1 -1
  13. package/dist/convert/composition-to-pdf.d.ts +1 -1
  14. package/dist/convert/composition-to-pdf.js +2 -2
  15. package/dist/convert/composition.cjs +16 -511
  16. package/dist/convert/composition.d.cts +2 -85
  17. package/dist/convert/composition.d.ts +2 -85
  18. package/dist/convert/composition.js +2 -502
  19. package/dist/convert/convert.cjs +2 -2
  20. package/dist/convert/convert.js +1 -1
  21. package/dist/convert/from-package.cjs +3 -3
  22. package/dist/convert/from-package.js +2 -2
  23. package/dist/convert/from-pdf.cjs +18 -18
  24. package/dist/convert/from-pdf.js +2 -2
  25. package/dist/convert/local.cjs +3 -3
  26. package/dist/convert/local.js +1 -1
  27. package/dist/edit/odp/slide.cjs +4 -4
  28. package/dist/edit/odp/slide.d.cts +1 -1
  29. package/dist/edit/odp/slide.d.ts +1 -1
  30. package/dist/edit/odp/slide.js +1 -1
  31. package/dist/edit/odt/content.d.cts +1 -1
  32. package/dist/edit/odt/content.d.ts +1 -1
  33. package/dist/edit/odt/editor.cjs +4 -4
  34. package/dist/edit/odt/editor.d.cts +1 -1
  35. package/dist/edit/odt/editor.d.ts +1 -1
  36. package/dist/edit/odt/editor.js +1 -1
  37. package/dist/edit/odt/table-grid.cjs +23 -0
  38. package/dist/edit/odt/table-grid.d.cts +54 -0
  39. package/dist/edit/odt/table-grid.d.ts +54 -0
  40. package/dist/edit/odt/table-grid.js +2 -0
  41. package/dist/edit/odt/table.cjs +12 -653
  42. package/dist/edit/odt/table.d.cts +2 -2
  43. package/dist/edit/odt/table.d.ts +2 -2
  44. package/dist/edit/odt/table.js +2 -647
  45. package/dist/{evaluate-BbOsgdmN.d.cts → evaluate-BSEUxiUK.d.cts} +3 -1
  46. package/dist/evaluate-CEzsBx3w.cjs +564 -0
  47. package/dist/{evaluate-C7fmk69X.d.ts → evaluate-D8fG2ZeB.d.ts} +3 -1
  48. package/dist/evaluate-IK-3aMv5.js +445 -0
  49. package/dist/evaluate-columns-CyqKHkIW.d.cts +41 -0
  50. package/dist/evaluate-columns-cOo8fOfT.d.ts +41 -0
  51. package/dist/index.cjs +24 -24
  52. package/dist/index.d.cts +6 -5
  53. package/dist/index.d.ts +6 -5
  54. package/dist/index.js +8 -8
  55. package/dist/latex/lint.cjs +2 -2
  56. package/dist/latex/lint.js +1 -1
  57. package/dist/latex/lower-fold.cjs +6 -0
  58. package/dist/latex/lower-fold.d.cts +17 -0
  59. package/dist/latex/lower-fold.d.ts +17 -0
  60. package/dist/latex/lower-fold.js +2 -0
  61. package/dist/latex/lower.cjs +11 -617
  62. package/dist/latex/lower.d.cts +18 -1
  63. package/dist/latex/lower.d.ts +18 -1
  64. package/dist/latex/lower.js +2 -616
  65. package/dist/latex/symbols.d.cts +1 -15
  66. package/dist/latex/symbols.d.ts +1 -15
  67. package/dist/latex/temml.d.cts +1 -24
  68. package/dist/latex/temml.d.ts +1 -24
  69. package/dist/layout/engine.cjs +2 -2
  70. package/dist/layout/engine.js +1 -1
  71. package/dist/layout/reconstruct-lines.cjs +315 -0
  72. package/dist/layout/reconstruct-lines.d.cts +2 -0
  73. package/dist/layout/reconstruct-lines.d.ts +2 -0
  74. package/dist/layout/reconstruct-lines.js +297 -0
  75. package/dist/layout/reconstruct-presentations-prod.cjs +9 -0
  76. package/dist/layout/reconstruct-presentations-prod.d.cts +26 -0
  77. package/dist/layout/reconstruct-presentations-prod.d.ts +26 -0
  78. package/dist/layout/reconstruct-presentations-prod.js +2 -0
  79. package/dist/layout/reconstruct-tables.cjs +5 -0
  80. package/dist/layout/reconstruct-tables.d.cts +22 -0
  81. package/dist/layout/reconstruct-tables.d.ts +22 -0
  82. package/dist/layout/reconstruct-tables.js +2 -0
  83. package/dist/layout/reconstruct.cjs +11 -1545
  84. package/dist/layout/reconstruct.d.cts +2 -14
  85. package/dist/layout/reconstruct.d.ts +2 -14
  86. package/dist/layout/reconstruct.js +2 -1542
  87. package/dist/layout/shared.cjs +2 -2
  88. package/dist/layout/shared.js +1 -1
  89. package/dist/layout/sheets-render.cjs +19 -0
  90. package/dist/layout/sheets-render.d.cts +41 -0
  91. package/dist/layout/sheets-render.d.ts +41 -0
  92. package/dist/layout/sheets-render.js +2 -0
  93. package/dist/layout/sheets.cjs +10 -544
  94. package/dist/layout/sheets.d.cts +13 -2
  95. package/dist/layout/sheets.d.ts +13 -2
  96. package/dist/layout/sheets.js +2 -543
  97. package/dist/layout/slides.cjs +2 -2
  98. package/dist/layout/slides.js +1 -1
  99. package/dist/layout-DIJzJk4x.js +526 -0
  100. package/dist/layout-iuiyl_Fk.cjs +621 -0
  101. package/dist/layout-types-oSbHvZid.d.cts +13 -0
  102. package/dist/layout-types-oSbHvZid.d.ts +13 -0
  103. package/dist/lower-DCs3rWI7.js +618 -0
  104. package/dist/lower-DzOb13w4.cjs +701 -0
  105. package/dist/markdown/math.cjs +2 -2
  106. package/dist/markdown/math.js +1 -1
  107. package/dist/mathml/layout-stretch.cjs +16 -0
  108. package/dist/mathml/layout-stretch.d.cts +24 -0
  109. package/dist/mathml/layout-stretch.d.ts +24 -0
  110. package/dist/mathml/layout-stretch.js +2 -0
  111. package/dist/mathml/layout-types.d.cts +1 -12
  112. package/dist/mathml/layout-types.d.ts +1 -12
  113. package/dist/mathml/layout.cjs +3 -525
  114. package/dist/mathml/layout.d.cts +2 -2
  115. package/dist/mathml/layout.d.ts +2 -2
  116. package/dist/mathml/layout.js +1 -523
  117. package/dist/odb/formula/evaluate.d.cts +1 -1
  118. package/dist/odb/formula/evaluate.d.ts +1 -1
  119. package/dist/odb/report/render.d.cts +1 -1
  120. package/dist/odb/report/render.d.ts +1 -1
  121. package/dist/odb/report/source.cjs +2 -2
  122. package/dist/odb/report/source.d.cts +1 -1
  123. package/dist/odb/report/source.d.ts +1 -1
  124. package/dist/odb/report/source.js +1 -1
  125. package/dist/odb/sql/evaluate-columns.cjs +122 -0
  126. package/dist/odb/sql/evaluate-columns.d.cts +2 -0
  127. package/dist/odb/sql/evaluate-columns.d.ts +2 -0
  128. package/dist/odb/sql/evaluate-columns.js +114 -0
  129. package/dist/odb/sql/evaluate-predicates.cjs +16 -0
  130. package/dist/odb/sql/evaluate-predicates.d.cts +23 -0
  131. package/dist/odb/sql/evaluate-predicates.d.ts +23 -0
  132. package/dist/odb/sql/evaluate-predicates.js +2 -0
  133. package/dist/odb/sql/evaluate.cjs +7 -556
  134. package/dist/odb/sql/evaluate.d.cts +2 -2
  135. package/dist/odb/sql/evaluate.d.ts +2 -2
  136. package/dist/odb/sql/evaluate.js +2 -552
  137. package/dist/read-BSH--XB4.js +682 -0
  138. package/dist/read-CahCZMwG.cjs +759 -0
  139. package/dist/reconstruct-BKOCAedo.d.ts +29 -0
  140. package/dist/reconstruct-D4TEteZ6.d.cts +29 -0
  141. package/dist/reconstruct-lines-B7t66ICm.d.cts +33 -0
  142. package/dist/reconstruct-lines-B7t66ICm.d.ts +33 -0
  143. package/dist/reconstruct-presentations-prod-B5fkPiRZ.js +1256 -0
  144. package/dist/reconstruct-presentations-prod-X315aBmI.cjs +1375 -0
  145. package/dist/sheets-BQCpNXsE.cjs +700 -0
  146. package/dist/sheets-DWDvGN-g.js +545 -0
  147. package/dist/svg/read-geometry.cjs +10 -0
  148. package/dist/svg/read-geometry.d.cts +24 -0
  149. package/dist/svg/read-geometry.d.ts +24 -0
  150. package/dist/svg/read-geometry.js +2 -0
  151. package/dist/svg/read.cjs +6 -680
  152. package/dist/svg/read.d.cts +17 -2
  153. package/dist/svg/read.d.ts +17 -2
  154. package/dist/svg/read.js +2 -679
  155. package/dist/symbols-BlzXfLEe.d.cts +16 -0
  156. package/dist/symbols-CKm2r4D0.d.ts +16 -0
  157. package/dist/table-B5gSMY7w.js +649 -0
  158. package/dist/{table-DrE6jEWv.d.cts → table-BK_Ao-Y6.d.cts} +9 -1
  159. package/dist/{table-B5htMG3g.d.ts → table-CxY85YUj.d.ts} +9 -1
  160. package/dist/table-DqUIOSPV.cjs +840 -0
  161. package/dist/temml-1-I9N9DD.d.cts +25 -0
  162. package/dist/temml-1-I9N9DD.d.ts +25 -0
  163. package/package.json +1 -1
@@ -0,0 +1,102 @@
1
+ import { t as ClockPort } from "./clock-Cewekmhw.cjs";
2
+ import { DocumentFormat } from "./convert/port.cjs";
3
+ import { t as ContentVariant } from "./capability-WJWAE-5Z.cjs";
4
+ import { i as SvgDiagnosticSink } from "./diagnostics-DVAXKgcf.cjs";
5
+ import { i as CellTypeInferenceSink } from "./cell-typing-BQ-xQ5X5.cjs";
6
+ import { a as ReconstructOptions } from "./reconstruct-D4TEteZ6.cjs";
7
+ import { t as OmmlDiagnostic } from "./shared-c0Lp3_iY.cjs";
8
+ import { ContentDocument, DocumentTree, FontSubstitution, ProvidedFont } from "document-schema.js";
9
+ import { LayoutDocument, PdfDiagnosticSink, WinAnsiSubstitution } from "pdf-codec";
10
+ import { MarkdownImageResolver } from "markdown-codec";
11
+ import { Package } from "ooxml.js";
12
+ //#region src/convert/composition.d.ts
13
+ declare const THROUGH_PDF_EDGE_COST = 3;
14
+ declare const MAX_CONVERSION_PATH_NODES = 4;
15
+ declare const FORMAT_NODES: Readonly<Record<ContentFormat, FormatNode>>;
16
+ type SourcePackage = Package;
17
+ interface UnifiedConversionOptions {
18
+ readonly signal?: AbortSignal;
19
+ readonly onDocument?: (pkg: DocumentTree) => void;
20
+ readonly fonts?: readonly ProvidedFont[];
21
+ readonly onFontSubstitution?: (substitution: FontSubstitution) => void;
22
+ readonly onSubstitution?: (substitution: WinAnsiSubstitution, context: {
23
+ readonly pageIndex: number;
24
+ }) => void;
25
+ readonly sink?: PdfDiagnosticSink;
26
+ readonly onMathDiagnostic?: (diagnostic: OmmlDiagnostic, context: {
27
+ readonly sourcePath?: string;
28
+ }) => void;
29
+ readonly images?: MarkdownImageResolver;
30
+ readonly delimiter?: string;
31
+ readonly sheet?: string;
32
+ readonly onCellTypeInference?: CellTypeInferenceSink;
33
+ readonly page?: number;
34
+ readonly onSvgDiagnostic?: SvgDiagnosticSink;
35
+ readonly clock?: ClockPort;
36
+ }
37
+ type ContentFormat = "docx" | "pptx" | "xlsx" | "odt" | "odp" | "ods" | "odg" | "svg" | "csv" | "markdown" | "rtf" | "doc" | "xls" | "ppt" | "epub";
38
+ declare const CONTENT_FORMATS: readonly ContentFormat[];
39
+ type LayoutVariant = Exclude<ContentVariant, "formula">;
40
+ interface PackageFormatNode {
41
+ readonly variant: LayoutVariant;
42
+ readonly family: "ooxml" | "odf";
43
+ readonly decode: (bytes: Uint8Array<ArrayBuffer>) => SourcePackage;
44
+ readonly read: (pkg: SourcePackage, options?: UnifiedConversionOptions) => ContentDocument;
45
+ readonly build: (content: ContentDocument, options?: UnifiedConversionOptions) => SourcePackage;
46
+ readonly encode: (pkg: SourcePackage) => Uint8Array<ArrayBuffer>;
47
+ readonly hasSourcePackage: true;
48
+ }
49
+ interface TextFormatNode {
50
+ readonly variant: LayoutVariant;
51
+ readonly family: "markdown" | "csv" | "svg" | "rtf" | "doc" | "xls" | "ppt" | "epub";
52
+ readonly decode: (bytes: Uint8Array<ArrayBuffer>) => string;
53
+ readonly read: (text: string, options?: UnifiedConversionOptions) => ContentDocument;
54
+ readonly build: (content: ContentDocument, options?: UnifiedConversionOptions) => string;
55
+ readonly encode: (text: string) => Uint8Array<ArrayBuffer>;
56
+ readonly hasSourcePackage: false;
57
+ }
58
+ type FormatNode = PackageFormatNode | TextFormatNode;
59
+ declare function isTextFormatNode(node: FormatNode): node is TextFormatNode;
60
+ type ReadOnlyContentFormat = "wpd";
61
+ declare const READ_ONLY_CONTENT_FORMATS: readonly ReadOnlyContentFormat[];
62
+ interface ReadOnlyFormatNode {
63
+ readonly variant: LayoutVariant;
64
+ readonly read: (bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => ContentDocument;
65
+ }
66
+ declare const READ_ONLY_FORMAT_NODES: Readonly<Record<ReadOnlyContentFormat, ReadOnlyFormatNode>>;
67
+ type SourceContentFormat = ContentFormat | ReadOnlyContentFormat;
68
+ declare function isReadOnlyContentFormat(format: DocumentFormat): format is ReadOnlyContentFormat;
69
+ declare const LAYOUT_CAPABLE: ReadonlySet<SourceContentFormat>;
70
+ declare const TRANSFORMS: Readonly<Record<string, (doc: ContentDocument) => ContentDocument>>;
71
+ declare const RECONSTRUCTORS: Readonly<Record<LayoutVariant, (doc: LayoutDocument, options?: ReconstructOptions) => ContentDocument>>;
72
+ declare function executeBridge(source: SourceContentFormat, target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
73
+ declare function executeFromPdf(target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
74
+ interface CompositionExecutorBinding {
75
+ readonly bridge: (source: SourceContentFormat, target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => Uint8Array<ArrayBuffer>;
76
+ readonly fromPdf: (target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => Uint8Array<ArrayBuffer>;
77
+ readonly toPdf?: (source: SourceContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions) => Uint8Array<ArrayBuffer>;
78
+ }
79
+ declare function runCompositionPlan(plan: ConversionPlan, bytes: Uint8Array<ArrayBuffer>, options: UnifiedConversionOptions | undefined, executors: CompositionExecutorBinding): Uint8Array<ArrayBuffer>;
80
+ declare function convertDocumentFromPdf(target: ContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
81
+ //#endregion
82
+ //#region src/convert/composition-plan.d.ts
83
+ type HopExecutor = "bridge" | "toPdf" | "fromPdf";
84
+ interface CompositionHop {
85
+ readonly executor: HopExecutor;
86
+ readonly from: DocumentFormat;
87
+ readonly to: DocumentFormat;
88
+ }
89
+ interface ConversionPlan {
90
+ readonly hops: readonly CompositionHop[];
91
+ }
92
+ interface GraphEdge {
93
+ readonly to: DocumentFormat;
94
+ readonly cost: number;
95
+ }
96
+ declare function buildCompositionGraph(): ReadonlyMap<DocumentFormat, readonly GraphEdge[]>;
97
+ declare function shortestPath(source: DocumentFormat, target: DocumentFormat): readonly DocumentFormat[] | undefined;
98
+ declare function resolveCompositionPlan(source: DocumentFormat, target: DocumentFormat): ConversionPlan | undefined;
99
+ declare function isContentFormat(format: DocumentFormat): format is ContentFormat;
100
+ declare function isSourceContentFormat(format: DocumentFormat): format is SourceContentFormat;
101
+ //#endregion
102
+ export { isTextFormatNode as A, THROUGH_PDF_EDGE_COST as C, executeBridge as D, convertDocumentFromPdf as E, executeFromPdf as O, SourceContentFormat as S, UnifiedConversionOptions as T, READ_ONLY_CONTENT_FORMATS as _, buildCompositionGraph as a, ReadOnlyContentFormat as b, resolveCompositionPlan as c, CompositionExecutorBinding as d, ContentFormat as f, MAX_CONVERSION_PATH_NODES as g, LAYOUT_CAPABLE as h, HopExecutor as i, runCompositionPlan as j, isReadOnlyContentFormat as k, shortestPath as l, FormatNode as m, ConversionPlan as n, isContentFormat as o, FORMAT_NODES as p, GraphEdge as r, isSourceContentFormat as s, CompositionHop as t, CONTENT_FORMATS as u, READ_ONLY_FORMAT_NODES as v, TRANSFORMS as w, ReadOnlyFormatNode as x, RECONSTRUCTORS as y };
@@ -0,0 +1,508 @@
1
+ import { decodeSvgText, encodeSvgText } from "./svg/text.js";
2
+ import { requireArrayBufferBytes } from "./model/bytes.js";
3
+ import { buildDocxPackage } from "./edit/docx/content.js";
4
+ import { buildPptxPackage } from "./edit/pptx/content.js";
5
+ import { buildOdtPackage } from "./edit/odt/content.js";
6
+ import { buildOdpPackage } from "./edit/odp/content.js";
7
+ import { buildOdsPackage } from "./edit/ods/content.js";
8
+ import { buildOdgPackage } from "./edit/odg/content.js";
9
+ import { buildMarkdownText } from "./markdown/write.js";
10
+ import { readMarkdownContent as readMarkdownContent$1 } from "./markdown/read.js";
11
+ import { t as readPptContent } from "./read--7mUJ4w7.js";
12
+ import { writePptContent } from "./ppt/write.js";
13
+ import { readDocxContent as readDocxContent$1 } from "./ooxml/docx/read.js";
14
+ import { readPptxContent as readPptxContent$1 } from "./ooxml/pptx/read.js";
15
+ import { readOdtContent as readOdtContent$1 } from "./odf/odt/read.js";
16
+ import { readOdpContent as readOdpContent$1 } from "./odf/odp/read.js";
17
+ import { readOdsContent as readOdsContent$1 } from "./odf/ods/read.js";
18
+ import { readOdgContent as readOdgContent$1 } from "./odf/odg/read.js";
19
+ import { decodeMarkdownText, encodeMarkdownText } from "./markdown/text.js";
20
+ import { decodeCsvText, encodeCsvText } from "./csv/text.js";
21
+ import { readCsvContent } from "./csv/read.js";
22
+ import { buildCsvText } from "./csv/write.js";
23
+ import { i as readSvgContent } from "./read-BSH--XB4.js";
24
+ import { buildSvgText } from "./svg/write.js";
25
+ import { throwIfAborted } from "./ports/abort.js";
26
+ import { _ as reconstructWordprocessing, g as reconstructSpreadsheet, i as reconstructPresentation, r as reconstructDrawing } from "./reconstruct-presentations-prod-B5fkPiRZ.js";
27
+ import { stampPdfPackageTables } from "./convert/pdf-package-tables.js";
28
+ import { drawingToPresentation, presentationToDrawing, presentationToWordprocessing, spreadsheetToWordprocessing, wordprocessingToPresentation } from "./convert/variant-bridges.js";
29
+ import { UnsupportedConversionError } from "./convert/capability.js";
30
+ import { buildXlsxPackageFromContent, decodePackage, encodePackage, readXlsxContent } from "ooxml.js";
31
+ import { assembleTree } from "document-schema.js";
32
+ import { decodePackage as decodePackage$1, encodePackage as encodePackage$1 } from "odf.js";
33
+ import { readDocContent, writeDocContent } from "doc-codec";
34
+ import { readXlsContent, writeXlsContent } from "xls-codec";
35
+ import { readRtfContent, rtfBytesFromLatin1, writeRtfContent } from "rtf-codec";
36
+ import { readEpubContent, writeEpubContent } from "epub-codec";
37
+ import "markdown-codec";
38
+ import { readWpdContent } from "wpd-codec";
39
+ import { readPdf } from "pdf-codec/read";
40
+ //#region src/convert/composition.ts
41
+ const LATIN1_MAX_CODE = 255;
42
+ const HEX_RADIX = 16;
43
+ const UNICODE_HEX_DIGITS = 4;
44
+ const THROUGH_PDF_EDGE_COST = 3;
45
+ const MAX_CONVERSION_PATH_NODES = 4;
46
+ const FORMAT_NODES = {
47
+ docx: {
48
+ variant: "wordprocessing",
49
+ family: "ooxml",
50
+ decode: (bytes) => decodePackage(bytes),
51
+ read: (pkg, options) => readDocxContent$1(pkg, { onMathDiagnostic: options?.onMathDiagnostic }),
52
+ build: (content, options) => buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }),
53
+ encode: (pkg) => encodePackage(pkg),
54
+ hasSourcePackage: true
55
+ },
56
+ pptx: {
57
+ variant: "presentation",
58
+ family: "ooxml",
59
+ decode: (bytes) => decodePackage(bytes),
60
+ read: (pkg, options) => readPptxContent$1(pkg, { onMathDiagnostic: options?.onMathDiagnostic }),
61
+ build: (content, options) => buildPptxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }),
62
+ encode: (pkg) => encodePackage(pkg),
63
+ hasSourcePackage: true
64
+ },
65
+ xlsx: {
66
+ variant: "spreadsheet",
67
+ family: "ooxml",
68
+ decode: (bytes) => decodePackage(bytes),
69
+ read: (pkg) => readXlsxContent(pkg),
70
+ build: (content) => buildXlsxPackageFromContent(content),
71
+ encode: (pkg) => encodePackage(pkg),
72
+ hasSourcePackage: true
73
+ },
74
+ odt: {
75
+ variant: "wordprocessing",
76
+ family: "odf",
77
+ decode: (bytes) => decodePackage$1(bytes),
78
+ read: (pkg) => readOdtContent$1(pkg),
79
+ build: (content) => buildOdtPackage(content),
80
+ encode: (pkg) => encodePackage$1(pkg),
81
+ hasSourcePackage: true
82
+ },
83
+ odp: {
84
+ variant: "presentation",
85
+ family: "odf",
86
+ decode: (bytes) => decodePackage$1(bytes),
87
+ read: (pkg) => readOdpContent$1(pkg),
88
+ build: (content) => buildOdpPackage(content),
89
+ encode: (pkg) => encodePackage$1(pkg),
90
+ hasSourcePackage: true
91
+ },
92
+ ods: {
93
+ variant: "spreadsheet",
94
+ family: "odf",
95
+ decode: (bytes) => decodePackage$1(bytes),
96
+ read: (pkg) => readOdsContent$1(pkg),
97
+ build: (content) => buildOdsPackage(content),
98
+ encode: (pkg) => encodePackage$1(pkg),
99
+ hasSourcePackage: true
100
+ },
101
+ odg: {
102
+ variant: "drawing",
103
+ family: "odf",
104
+ decode: (bytes) => decodePackage$1(bytes),
105
+ read: (pkg) => readOdgContent$1(pkg),
106
+ build: (content) => buildOdgPackage(content),
107
+ encode: (pkg) => encodePackage$1(pkg),
108
+ hasSourcePackage: true
109
+ },
110
+ svg: {
111
+ variant: "drawing",
112
+ family: "svg",
113
+ decode: (bytes) => decodeSvgText(bytes),
114
+ read: (text, options) => readSvgContent(text, { onSvgDiagnostic: options?.onSvgDiagnostic }),
115
+ build: (content, options) => buildSvgText(content, {
116
+ page: options?.page,
117
+ onSvgDiagnostic: options?.onSvgDiagnostic
118
+ }),
119
+ encode: (text) => encodeSvgText(text),
120
+ hasSourcePackage: false
121
+ },
122
+ markdown: {
123
+ variant: "wordprocessing",
124
+ family: "markdown",
125
+ decode: (bytes) => decodeMarkdownText(bytes),
126
+ read: (text, options) => readMarkdownContent$1(text, {
127
+ signal: options?.signal,
128
+ images: options?.images
129
+ }),
130
+ build: (content) => buildMarkdownText(content),
131
+ encode: (text) => encodeMarkdownText(text),
132
+ hasSourcePackage: false
133
+ },
134
+ csv: {
135
+ variant: "spreadsheet",
136
+ family: "csv",
137
+ decode: (bytes) => decodeCsvText(bytes),
138
+ read: (text, options) => readCsvContent(text, {
139
+ delimiter: options?.delimiter,
140
+ onCellTypeInference: options?.onCellTypeInference
141
+ }),
142
+ build: (content, options) => buildCsvText(content, {
143
+ delimiter: options?.delimiter,
144
+ sheet: options?.sheet
145
+ }),
146
+ encode: (text) => encodeCsvText(text),
147
+ hasSourcePackage: false
148
+ },
149
+ rtf: {
150
+ variant: "wordprocessing",
151
+ family: "rtf",
152
+ decode: (bytes) => bytesToLatin1(bytes),
153
+ read: (text, options) => readRtfContent(text, { signal: options?.signal }).document,
154
+ build: (content) => bytesToLatin1(writeRtfContent(content)),
155
+ encode: (text) => requireArrayBufferBytes(rtfBytesFromLatin1(text)),
156
+ hasSourcePackage: false
157
+ },
158
+ doc: {
159
+ variant: "wordprocessing",
160
+ family: "doc",
161
+ decode: (bytes) => bytesToLatin1(bytes),
162
+ read: (text, options) => {
163
+ throwIfAborted(options?.signal);
164
+ return readDocContent(latin1ToBytes(text));
165
+ },
166
+ build: (content) => bytesToLatin1(writeDocContent(content)),
167
+ encode: (text) => latin1ToBytes(text),
168
+ hasSourcePackage: false
169
+ },
170
+ epub: {
171
+ variant: "wordprocessing",
172
+ family: "epub",
173
+ decode: (bytes) => bytesToLatin1(bytes),
174
+ read: (text, options) => {
175
+ throwIfAborted(options?.signal);
176
+ return readEpubContent(latin1ToBytes(text));
177
+ },
178
+ build: (content) => bytesToLatin1(writeEpubContent(content)),
179
+ encode: (text) => latin1ToBytes(text),
180
+ hasSourcePackage: false
181
+ },
182
+ xls: {
183
+ variant: "spreadsheet",
184
+ family: "xls",
185
+ decode: (bytes) => bytesToLatin1(bytes),
186
+ read: (text, options) => {
187
+ throwIfAborted(options?.signal);
188
+ return readXlsContent(latin1ToBytes(text));
189
+ },
190
+ build: (content) => {
191
+ if (content.kind !== "spreadsheet") throw new Error("FORMAT_NODES.xls.build: expected a spreadsheet ContentDocument");
192
+ return bytesToLatin1(writeXlsContent(content));
193
+ },
194
+ encode: (text) => latin1ToBytes(text),
195
+ hasSourcePackage: false
196
+ },
197
+ ppt: {
198
+ variant: "presentation",
199
+ family: "ppt",
200
+ decode: (bytes) => bytesToLatin1(bytes),
201
+ read: (text, options) => {
202
+ throwIfAborted(options?.signal);
203
+ return readPptContent(latin1ToBytes(text));
204
+ },
205
+ build: (content) => bytesToLatin1(writePptContent(content)),
206
+ encode: (text) => latin1ToBytes(text),
207
+ hasSourcePackage: false
208
+ }
209
+ };
210
+ const CONTENT_FORMATS = [
211
+ "docx",
212
+ "pptx",
213
+ "xlsx",
214
+ "odt",
215
+ "odp",
216
+ "ods",
217
+ "odg",
218
+ "svg",
219
+ "csv",
220
+ "markdown",
221
+ "rtf",
222
+ "doc",
223
+ "xls",
224
+ "ppt",
225
+ "epub"
226
+ ];
227
+ function isTextFormatNode(node) {
228
+ return !node.hasSourcePackage;
229
+ }
230
+ const READ_ONLY_CONTENT_FORMATS = ["wpd"];
231
+ const READ_ONLY_FORMAT_NODES = { wpd: {
232
+ variant: "wordprocessing",
233
+ read: (bytes) => readWpdContent(bytes)
234
+ } };
235
+ function isReadOnlyContentFormat(format) {
236
+ return READ_ONLY_CONTENT_FORMATS.includes(format);
237
+ }
238
+ function readSourceContent(format, bytes, options) {
239
+ if (isReadOnlyContentFormat(format)) {
240
+ const node = READ_ONLY_FORMAT_NODES[format];
241
+ return {
242
+ content: node.read(bytes, options),
243
+ variant: node.variant
244
+ };
245
+ }
246
+ const node = FORMAT_NODES[format];
247
+ if (isTextFormatNode(node)) {
248
+ const text = node.decode(bytes);
249
+ return {
250
+ content: node.read(text, options),
251
+ variant: node.variant
252
+ };
253
+ }
254
+ const pkg = node.decode(bytes);
255
+ return {
256
+ content: node.read(pkg, options),
257
+ variant: node.variant
258
+ };
259
+ }
260
+ const LATIN1_CHUNK_SIZE = 8192;
261
+ function bytesToLatin1(bytes) {
262
+ let text = "";
263
+ for (let start = 0; start < bytes.length; start += LATIN1_CHUNK_SIZE) text += String.fromCharCode(...bytes.subarray(start, start + LATIN1_CHUNK_SIZE));
264
+ return text;
265
+ }
266
+ function latin1ToBytes(text) {
267
+ const bytes = new Uint8Array(text.length);
268
+ for (let index = 0; index < text.length; index += 1) {
269
+ const code = text.charCodeAt(index);
270
+ if (code > LATIN1_MAX_CODE) throw new TypeError(`latin1ToBytes: character at index ${String(index)} is U+${code.toString(HEX_RADIX).toUpperCase().padStart(UNICODE_HEX_DIGITS, "0")}, above U+00FF — this string no longer holds the file's original bytes`);
271
+ bytes[index] = code;
272
+ }
273
+ return bytes;
274
+ }
275
+ const LAYOUT_CAPABLE = /* @__PURE__ */ new Set([
276
+ "docx",
277
+ "pptx",
278
+ "odt",
279
+ "odp",
280
+ "ods",
281
+ "odg",
282
+ "svg",
283
+ "markdown",
284
+ "wpd"
285
+ ]);
286
+ const TRANSFORMS = {
287
+ "wordprocessing->presentation": (doc) => {
288
+ if (doc.kind !== "wordprocessing") throw new Error("wordprocessingToPresentation: expected a wordprocessing ContentDocument");
289
+ return wordprocessingToPresentation(doc);
290
+ },
291
+ "presentation->wordprocessing": (doc) => {
292
+ if (doc.kind !== "presentation") throw new Error("presentationToWordprocessing: expected a presentation ContentDocument");
293
+ return presentationToWordprocessing(doc);
294
+ },
295
+ "drawing->presentation": (doc) => {
296
+ if (doc.kind !== "drawing") throw new Error("drawingToPresentation: expected a drawing ContentDocument");
297
+ return drawingToPresentation(doc);
298
+ },
299
+ "presentation->drawing": (doc) => {
300
+ if (doc.kind !== "presentation") throw new Error("presentationToDrawing: expected a presentation ContentDocument");
301
+ return presentationToDrawing(doc);
302
+ },
303
+ "spreadsheet->wordprocessing": (doc) => {
304
+ if (doc.kind !== "spreadsheet") throw new Error("spreadsheetToWordprocessing: expected a spreadsheet ContentDocument");
305
+ return spreadsheetToWordprocessing(doc);
306
+ }
307
+ };
308
+ const RECONSTRUCTORS = {
309
+ wordprocessing: reconstructWordprocessing,
310
+ presentation: reconstructPresentation,
311
+ drawing: reconstructDrawing,
312
+ spreadsheet: reconstructSpreadsheet
313
+ };
314
+ function executeBridge(source, target, bytes, options) {
315
+ throwIfAborted(options?.signal);
316
+ const targetNode = FORMAT_NODES[target];
317
+ const { content, variant: sourceVariant } = readSourceContent(source, bytes, options);
318
+ if (content.kind !== sourceVariant) throw new Error(`executeBridge: ${source} read returned a non-${sourceVariant} ContentDocument`);
319
+ let buildContent = content;
320
+ if (sourceVariant !== targetNode.variant) {
321
+ const key = `${sourceVariant}->${targetNode.variant}`;
322
+ const transform = TRANSFORMS[key];
323
+ if (transform === void 0) throw new Error(`executeBridge: no transform registered for ${key}`);
324
+ buildContent = transform(content);
325
+ }
326
+ throwIfAborted(options?.signal);
327
+ let out;
328
+ if (isTextFormatNode(targetNode)) {
329
+ const text = targetNode.build(buildContent, options);
330
+ out = targetNode.encode(text);
331
+ } else {
332
+ const pkg = targetNode.build(buildContent, options);
333
+ out = targetNode.encode(pkg);
334
+ }
335
+ options?.onDocument?.(assembleTree(buildContent));
336
+ return out;
337
+ }
338
+ function executeFromPdf(target, bytes, options) {
339
+ const node = FORMAT_NODES[target];
340
+ const layout = readPdf(bytes, {
341
+ signal: options?.signal,
342
+ sink: options?.sink
343
+ });
344
+ const content = RECONSTRUCTORS[node.variant](layout, {
345
+ signal: options?.signal,
346
+ onCellTypeInference: options?.onCellTypeInference
347
+ });
348
+ const pages = layout.pages.map((page) => ({
349
+ widthPt: page.widthPt,
350
+ heightPt: page.heightPt
351
+ }));
352
+ let out;
353
+ if (isTextFormatNode(node)) {
354
+ const text = node.build(content, options);
355
+ out = node.encode(text);
356
+ } else {
357
+ const pkg = node.build(content);
358
+ out = node.encode(pkg);
359
+ }
360
+ const reported = assembleTree(content, pages);
361
+ stampPdfPackageTables(reported, layout);
362
+ options?.onDocument?.(reported);
363
+ return out;
364
+ }
365
+ function runCompositionPlan(plan, bytes, options, executors) {
366
+ let current = bytes;
367
+ for (let i = 0; i < plan.hops.length; i++) {
368
+ const hop = plan.hops[i];
369
+ if (hop === void 0) throw new Error("runCompositionPlan: resolveCompositionPlan returned a malformed hop");
370
+ const hopOptions = i === plan.hops.length - 1 ? options : options === void 0 ? void 0 : {
371
+ ...options,
372
+ onDocument: void 0
373
+ };
374
+ if (hop.executor === "toPdf") {
375
+ if (!isSourceContentFormat(hop.from)) throw new Error(`runCompositionPlan: toPdf source '${hop.from}' is not a content format`);
376
+ const toPdf = executors.toPdf;
377
+ 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)`);
378
+ current = toPdf(hop.from, current, hopOptions);
379
+ } else if (hop.executor === "fromPdf") {
380
+ if (!isContentFormat(hop.to)) throw new Error(`runCompositionPlan: fromPdf target '${hop.to}' is not a content format`);
381
+ current = executors.fromPdf(hop.to, current, hopOptions);
382
+ } else {
383
+ if (!isSourceContentFormat(hop.from) || !isContentFormat(hop.to)) throw new Error(`runCompositionPlan: bridge endpoints '${hop.from}' -> '${hop.to}' are not both content formats`);
384
+ current = executors.bridge(hop.from, hop.to, current, hopOptions);
385
+ }
386
+ }
387
+ return current;
388
+ }
389
+ function convertDocumentFromPdf(target, bytes, options) {
390
+ const plan = resolveCompositionPlan("pdf", target);
391
+ if (plan === void 0) throw new UnsupportedConversionError("pdf", target);
392
+ return runCompositionPlan(plan, bytes, options, {
393
+ bridge: executeBridge,
394
+ fromPdf: executeFromPdf
395
+ });
396
+ }
397
+ //#endregion
398
+ //#region src/convert/composition-plan.ts
399
+ function buildCompositionGraph() {
400
+ const adj = /* @__PURE__ */ new Map();
401
+ const addDirected = (from, to, cost) => {
402
+ const list = adj.get(from);
403
+ if (list === void 0) adj.set(from, [{
404
+ to,
405
+ cost
406
+ }]);
407
+ else list.push({
408
+ to,
409
+ cost
410
+ });
411
+ };
412
+ const addEdge = (from, to, cost) => {
413
+ addDirected(from, to, cost);
414
+ addDirected(to, from, cost);
415
+ };
416
+ for (const a of CONTENT_FORMATS) for (const b of CONTENT_FORMATS) {
417
+ if (a === b) continue;
418
+ if (FORMAT_NODES[a].variant === FORMAT_NODES[b].variant) addEdge(a, b, 1);
419
+ }
420
+ for (const key of Object.keys(TRANSFORMS)) {
421
+ const parts = key.split("->");
422
+ const fromVariant = parts[0];
423
+ const toVariant = parts[1];
424
+ if (fromVariant === void 0 || toVariant === void 0) continue;
425
+ for (const a of CONTENT_FORMATS) {
426
+ if (FORMAT_NODES[a].variant !== fromVariant) continue;
427
+ for (const b of CONTENT_FORMATS) {
428
+ if (FORMAT_NODES[b].variant !== toVariant) continue;
429
+ addDirected(a, b, 2);
430
+ }
431
+ }
432
+ }
433
+ for (const format of CONTENT_FORMATS) if (LAYOUT_CAPABLE.has(format)) addEdge(format, "pdf", 3);
434
+ for (const source of READ_ONLY_CONTENT_FORMATS) {
435
+ const variant = READ_ONLY_FORMAT_NODES[source].variant;
436
+ for (const target of CONTENT_FORMATS) {
437
+ const targetVariant = FORMAT_NODES[target].variant;
438
+ if (targetVariant === variant) addDirected(source, target, 1);
439
+ else if (TRANSFORMS[`${variant}->${targetVariant}`] !== void 0) addDirected(source, target, 2);
440
+ }
441
+ if (LAYOUT_CAPABLE.has(source)) addDirected(source, "pdf", 3);
442
+ }
443
+ return adj;
444
+ }
445
+ let compositionGraphCache;
446
+ function compositionGraph() {
447
+ compositionGraphCache ??= buildCompositionGraph();
448
+ return compositionGraphCache;
449
+ }
450
+ function shortestPath(source, target) {
451
+ if (source === target) return;
452
+ const distances = /* @__PURE__ */ new Map([[source, 0]]);
453
+ const previous = /* @__PURE__ */ new Map();
454
+ const visited = /* @__PURE__ */ new Set();
455
+ while (true) {
456
+ let current = void 0;
457
+ let currentDist = Infinity;
458
+ for (const [node, dist] of distances) if (!visited.has(node) && dist < currentDist) {
459
+ current = node;
460
+ currentDist = dist;
461
+ }
462
+ if (current === void 0 || current === target) break;
463
+ visited.add(current);
464
+ for (const edge of compositionGraph().get(current) ?? []) {
465
+ if (visited.has(edge.to)) continue;
466
+ const alt = currentDist + edge.cost;
467
+ const known = distances.get(edge.to);
468
+ if (known === void 0 || alt < known) {
469
+ distances.set(edge.to, alt);
470
+ previous.set(edge.to, current);
471
+ }
472
+ }
473
+ }
474
+ if (distances.get(target) === void 0) return;
475
+ const path = [];
476
+ let cursor = target;
477
+ while (cursor !== void 0) {
478
+ path.unshift(cursor);
479
+ cursor = previous.get(cursor);
480
+ }
481
+ return path;
482
+ }
483
+ function resolveCompositionPlan(source, target) {
484
+ const path = shortestPath(source, target);
485
+ if (path === void 0) return;
486
+ if (path.length > 4) return;
487
+ const hops = [];
488
+ for (let i = 0; i + 1 < path.length; i++) {
489
+ const from = path[i];
490
+ const to = path[i + 1];
491
+ if (from === void 0 || to === void 0) return;
492
+ const executor = to === "pdf" ? "toPdf" : from === "pdf" ? "fromPdf" : "bridge";
493
+ hops.push({
494
+ executor,
495
+ from,
496
+ to
497
+ });
498
+ }
499
+ return { hops };
500
+ }
501
+ function isContentFormat(format) {
502
+ return format !== "pdf" && format !== "odf" && !isReadOnlyContentFormat(format);
503
+ }
504
+ function isSourceContentFormat(format) {
505
+ return isContentFormat(format) || isReadOnlyContentFormat(format);
506
+ }
507
+ //#endregion
508
+ export { executeFromPdf as _, shortestPath as a, runCompositionPlan as b, LAYOUT_CAPABLE as c, READ_ONLY_FORMAT_NODES as d, RECONSTRUCTORS as f, executeBridge as g, convertDocumentFromPdf as h, resolveCompositionPlan as i, MAX_CONVERSION_PATH_NODES as l, TRANSFORMS as m, isContentFormat as n, CONTENT_FORMATS as o, THROUGH_PDF_EDGE_COST as p, isSourceContentFormat as r, FORMAT_NODES as s, buildCompositionGraph as t, READ_ONLY_CONTENT_FORMATS as u, isReadOnlyContentFormat as v, isTextFormatNode as y };