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
@@ -13,7 +13,7 @@ const require_odf_odg_read = require("../odf/odg/read.cjs");
13
13
  const require_markdown_text = require("../markdown/text.cjs");
14
14
  const require_csv_text = require("../csv/text.cjs");
15
15
  const require_csv_read = require("../csv/read.cjs");
16
- const require_svg_read = require("../svg/read.cjs");
16
+ const require_read$1 = require("../read-CahCZMwG.cjs");
17
17
  const require_ports_abort = require("../ports/abort.cjs");
18
18
  const require_package_codec = require("../package-codec.cjs");
19
19
  let ooxml_js = require("ooxml.js");
@@ -58,7 +58,7 @@ const CONTENT_READERS = {
58
58
  images: options?.images
59
59
  }),
60
60
  csv: (bytes) => require_csv_read.readCsvContent(require_csv_text.decodeCsvText(bytes)),
61
- svg: (bytes) => require_svg_read.readSvgContent(require_svg_text.decodeSvgText(bytes)),
61
+ svg: (bytes) => require_read$1.readSvgContent(require_svg_text.decodeSvgText(bytes)),
62
62
  rtf: (bytes, options) => (0, rtf_codec.readRtfContent)(bytes, { signal: options?.signal }).document,
63
63
  doc: (bytes, options) => {
64
64
  require_ports_abort.throwIfAborted(options?.signal);
@@ -12,7 +12,7 @@ import { readOdgContent } from "../odf/odg/read.js";
12
12
  import { decodeMarkdownText } from "../markdown/text.js";
13
13
  import { decodeCsvText } from "../csv/text.js";
14
14
  import { readCsvContent } from "../csv/read.js";
15
- import { readSvgContent } from "../svg/read.js";
15
+ import { i as readSvgContent } from "../read-BSH--XB4.js";
16
16
  import { throwIfAborted } from "../ports/abort.js";
17
17
  import { decodeDocumentPackage } from "../package-codec.js";
18
18
  import { readXlsxContent } from "ooxml.js";
@@ -0,0 +1,627 @@
1
+ const require_svg_text = require("./svg/text.cjs");
2
+ const require_model_bytes = require("./model/bytes.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_write = require("./markdown/write.cjs");
10
+ const require_markdown_read = require("./markdown/read.cjs");
11
+ const require_read = require("./read-pPa9I8MO.cjs");
12
+ const require_ppt_write = require("./ppt/write.cjs");
13
+ const require_ooxml_docx_read = require("./ooxml/docx/read.cjs");
14
+ const require_ooxml_pptx_read = require("./ooxml/pptx/read.cjs");
15
+ const require_odf_odt_read = require("./odf/odt/read.cjs");
16
+ const require_odf_odp_read = require("./odf/odp/read.cjs");
17
+ const require_odf_ods_read = require("./odf/ods/read.cjs");
18
+ const require_odf_odg_read = require("./odf/odg/read.cjs");
19
+ const require_markdown_text = require("./markdown/text.cjs");
20
+ const require_csv_text = require("./csv/text.cjs");
21
+ const require_csv_read = require("./csv/read.cjs");
22
+ const require_csv_write = require("./csv/write.cjs");
23
+ const require_read$1 = require("./read-CahCZMwG.cjs");
24
+ const require_svg_write = require("./svg/write.cjs");
25
+ const require_ports_abort = require("./ports/abort.cjs");
26
+ const require_reconstruct_presentations_prod = require("./reconstruct-presentations-prod-X315aBmI.cjs");
27
+ const require_convert_pdf_package_tables = require("./convert/pdf-package-tables.cjs");
28
+ const require_convert_variant_bridges = require("./convert/variant-bridges.cjs");
29
+ const require_convert_capability = require("./convert/capability.cjs");
30
+ let ooxml_js = require("ooxml.js");
31
+ let document_schema_js = require("document-schema.js");
32
+ let odf_js = require("odf.js");
33
+ let doc_codec = require("doc-codec");
34
+ let xls_codec = require("xls-codec");
35
+ let rtf_codec = require("rtf-codec");
36
+ let epub_codec = require("epub-codec");
37
+ require("markdown-codec");
38
+ let wpd_codec = require("wpd-codec");
39
+ let pdf_codec_read = require("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) => (0, ooxml_js.decodePackage)(bytes),
51
+ read: (pkg, options) => require_ooxml_docx_read.readDocxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic }),
52
+ build: (content, options) => require_edit_docx_content.buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }),
53
+ encode: (pkg) => (0, ooxml_js.encodePackage)(pkg),
54
+ hasSourcePackage: true
55
+ },
56
+ pptx: {
57
+ variant: "presentation",
58
+ family: "ooxml",
59
+ decode: (bytes) => (0, ooxml_js.decodePackage)(bytes),
60
+ read: (pkg, options) => require_ooxml_pptx_read.readPptxContent(pkg, { onMathDiagnostic: options?.onMathDiagnostic }),
61
+ build: (content, options) => require_edit_pptx_content.buildPptxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }),
62
+ encode: (pkg) => (0, ooxml_js.encodePackage)(pkg),
63
+ hasSourcePackage: true
64
+ },
65
+ xlsx: {
66
+ variant: "spreadsheet",
67
+ family: "ooxml",
68
+ decode: (bytes) => (0, ooxml_js.decodePackage)(bytes),
69
+ read: (pkg) => (0, ooxml_js.readXlsxContent)(pkg),
70
+ build: (content) => (0, ooxml_js.buildXlsxPackageFromContent)(content),
71
+ encode: (pkg) => (0, ooxml_js.encodePackage)(pkg),
72
+ hasSourcePackage: true
73
+ },
74
+ odt: {
75
+ variant: "wordprocessing",
76
+ family: "odf",
77
+ decode: (bytes) => (0, odf_js.decodePackage)(bytes),
78
+ read: (pkg) => require_odf_odt_read.readOdtContent(pkg),
79
+ build: (content) => require_edit_odt_content.buildOdtPackage(content),
80
+ encode: (pkg) => (0, odf_js.encodePackage)(pkg),
81
+ hasSourcePackage: true
82
+ },
83
+ odp: {
84
+ variant: "presentation",
85
+ family: "odf",
86
+ decode: (bytes) => (0, odf_js.decodePackage)(bytes),
87
+ read: (pkg) => require_odf_odp_read.readOdpContent(pkg),
88
+ build: (content) => require_edit_odp_content.buildOdpPackage(content),
89
+ encode: (pkg) => (0, odf_js.encodePackage)(pkg),
90
+ hasSourcePackage: true
91
+ },
92
+ ods: {
93
+ variant: "spreadsheet",
94
+ family: "odf",
95
+ decode: (bytes) => (0, odf_js.decodePackage)(bytes),
96
+ read: (pkg) => require_odf_ods_read.readOdsContent(pkg),
97
+ build: (content) => require_edit_ods_content.buildOdsPackage(content),
98
+ encode: (pkg) => (0, odf_js.encodePackage)(pkg),
99
+ hasSourcePackage: true
100
+ },
101
+ odg: {
102
+ variant: "drawing",
103
+ family: "odf",
104
+ decode: (bytes) => (0, odf_js.decodePackage)(bytes),
105
+ read: (pkg) => require_odf_odg_read.readOdgContent(pkg),
106
+ build: (content) => require_edit_odg_content.buildOdgPackage(content),
107
+ encode: (pkg) => (0, odf_js.encodePackage)(pkg),
108
+ hasSourcePackage: true
109
+ },
110
+ svg: {
111
+ variant: "drawing",
112
+ family: "svg",
113
+ decode: (bytes) => require_svg_text.decodeSvgText(bytes),
114
+ read: (text, options) => require_read$1.readSvgContent(text, { onSvgDiagnostic: options?.onSvgDiagnostic }),
115
+ build: (content, options) => require_svg_write.buildSvgText(content, {
116
+ page: options?.page,
117
+ onSvgDiagnostic: options?.onSvgDiagnostic
118
+ }),
119
+ encode: (text) => require_svg_text.encodeSvgText(text),
120
+ hasSourcePackage: false
121
+ },
122
+ markdown: {
123
+ variant: "wordprocessing",
124
+ family: "markdown",
125
+ decode: (bytes) => require_markdown_text.decodeMarkdownText(bytes),
126
+ read: (text, options) => require_markdown_read.readMarkdownContent(text, {
127
+ signal: options?.signal,
128
+ images: options?.images
129
+ }),
130
+ build: (content) => require_markdown_write.buildMarkdownText(content),
131
+ encode: (text) => require_markdown_text.encodeMarkdownText(text),
132
+ hasSourcePackage: false
133
+ },
134
+ csv: {
135
+ variant: "spreadsheet",
136
+ family: "csv",
137
+ decode: (bytes) => require_csv_text.decodeCsvText(bytes),
138
+ read: (text, options) => require_csv_read.readCsvContent(text, {
139
+ delimiter: options?.delimiter,
140
+ onCellTypeInference: options?.onCellTypeInference
141
+ }),
142
+ build: (content, options) => require_csv_write.buildCsvText(content, {
143
+ delimiter: options?.delimiter,
144
+ sheet: options?.sheet
145
+ }),
146
+ encode: (text) => require_csv_text.encodeCsvText(text),
147
+ hasSourcePackage: false
148
+ },
149
+ rtf: {
150
+ variant: "wordprocessing",
151
+ family: "rtf",
152
+ decode: (bytes) => bytesToLatin1(bytes),
153
+ read: (text, options) => (0, rtf_codec.readRtfContent)(text, { signal: options?.signal }).document,
154
+ build: (content) => bytesToLatin1((0, rtf_codec.writeRtfContent)(content)),
155
+ encode: (text) => require_model_bytes.requireArrayBufferBytes((0, rtf_codec.rtfBytesFromLatin1)(text)),
156
+ hasSourcePackage: false
157
+ },
158
+ doc: {
159
+ variant: "wordprocessing",
160
+ family: "doc",
161
+ decode: (bytes) => bytesToLatin1(bytes),
162
+ read: (text, options) => {
163
+ require_ports_abort.throwIfAborted(options?.signal);
164
+ return (0, doc_codec.readDocContent)(latin1ToBytes(text));
165
+ },
166
+ build: (content) => bytesToLatin1((0, doc_codec.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
+ require_ports_abort.throwIfAborted(options?.signal);
176
+ return (0, epub_codec.readEpubContent)(latin1ToBytes(text));
177
+ },
178
+ build: (content) => bytesToLatin1((0, epub_codec.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
+ require_ports_abort.throwIfAborted(options?.signal);
188
+ return (0, xls_codec.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((0, xls_codec.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
+ require_ports_abort.throwIfAborted(options?.signal);
203
+ return require_read.readPptContent(latin1ToBytes(text));
204
+ },
205
+ build: (content) => bytesToLatin1(require_ppt_write.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) => (0, wpd_codec.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 require_convert_variant_bridges.wordprocessingToPresentation(doc);
290
+ },
291
+ "presentation->wordprocessing": (doc) => {
292
+ if (doc.kind !== "presentation") throw new Error("presentationToWordprocessing: expected a presentation ContentDocument");
293
+ return require_convert_variant_bridges.presentationToWordprocessing(doc);
294
+ },
295
+ "drawing->presentation": (doc) => {
296
+ if (doc.kind !== "drawing") throw new Error("drawingToPresentation: expected a drawing ContentDocument");
297
+ return require_convert_variant_bridges.drawingToPresentation(doc);
298
+ },
299
+ "presentation->drawing": (doc) => {
300
+ if (doc.kind !== "presentation") throw new Error("presentationToDrawing: expected a presentation ContentDocument");
301
+ return require_convert_variant_bridges.presentationToDrawing(doc);
302
+ },
303
+ "spreadsheet->wordprocessing": (doc) => {
304
+ if (doc.kind !== "spreadsheet") throw new Error("spreadsheetToWordprocessing: expected a spreadsheet ContentDocument");
305
+ return require_convert_variant_bridges.spreadsheetToWordprocessing(doc);
306
+ }
307
+ };
308
+ const RECONSTRUCTORS = {
309
+ wordprocessing: require_reconstruct_presentations_prod.reconstructWordprocessing,
310
+ presentation: require_reconstruct_presentations_prod.reconstructPresentation,
311
+ drawing: require_reconstruct_presentations_prod.reconstructDrawing,
312
+ spreadsheet: require_reconstruct_presentations_prod.reconstructSpreadsheet
313
+ };
314
+ function executeBridge(source, target, bytes, options) {
315
+ require_ports_abort.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
+ require_ports_abort.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?.((0, document_schema_js.assembleTree)(buildContent));
336
+ return out;
337
+ }
338
+ function executeFromPdf(target, bytes, options) {
339
+ const node = FORMAT_NODES[target];
340
+ const layout = (0, pdf_codec_read.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 = (0, document_schema_js.assembleTree)(content, pages);
361
+ require_convert_pdf_package_tables.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 require_convert_capability.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
+ Object.defineProperty(exports, "CONTENT_FORMATS", {
509
+ enumerable: true,
510
+ get: function() {
511
+ return CONTENT_FORMATS;
512
+ }
513
+ });
514
+ Object.defineProperty(exports, "FORMAT_NODES", {
515
+ enumerable: true,
516
+ get: function() {
517
+ return FORMAT_NODES;
518
+ }
519
+ });
520
+ Object.defineProperty(exports, "LAYOUT_CAPABLE", {
521
+ enumerable: true,
522
+ get: function() {
523
+ return LAYOUT_CAPABLE;
524
+ }
525
+ });
526
+ Object.defineProperty(exports, "MAX_CONVERSION_PATH_NODES", {
527
+ enumerable: true,
528
+ get: function() {
529
+ return MAX_CONVERSION_PATH_NODES;
530
+ }
531
+ });
532
+ Object.defineProperty(exports, "READ_ONLY_CONTENT_FORMATS", {
533
+ enumerable: true,
534
+ get: function() {
535
+ return READ_ONLY_CONTENT_FORMATS;
536
+ }
537
+ });
538
+ Object.defineProperty(exports, "READ_ONLY_FORMAT_NODES", {
539
+ enumerable: true,
540
+ get: function() {
541
+ return READ_ONLY_FORMAT_NODES;
542
+ }
543
+ });
544
+ Object.defineProperty(exports, "RECONSTRUCTORS", {
545
+ enumerable: true,
546
+ get: function() {
547
+ return RECONSTRUCTORS;
548
+ }
549
+ });
550
+ Object.defineProperty(exports, "THROUGH_PDF_EDGE_COST", {
551
+ enumerable: true,
552
+ get: function() {
553
+ return THROUGH_PDF_EDGE_COST;
554
+ }
555
+ });
556
+ Object.defineProperty(exports, "TRANSFORMS", {
557
+ enumerable: true,
558
+ get: function() {
559
+ return TRANSFORMS;
560
+ }
561
+ });
562
+ Object.defineProperty(exports, "buildCompositionGraph", {
563
+ enumerable: true,
564
+ get: function() {
565
+ return buildCompositionGraph;
566
+ }
567
+ });
568
+ Object.defineProperty(exports, "convertDocumentFromPdf", {
569
+ enumerable: true,
570
+ get: function() {
571
+ return convertDocumentFromPdf;
572
+ }
573
+ });
574
+ Object.defineProperty(exports, "executeBridge", {
575
+ enumerable: true,
576
+ get: function() {
577
+ return executeBridge;
578
+ }
579
+ });
580
+ Object.defineProperty(exports, "executeFromPdf", {
581
+ enumerable: true,
582
+ get: function() {
583
+ return executeFromPdf;
584
+ }
585
+ });
586
+ Object.defineProperty(exports, "isContentFormat", {
587
+ enumerable: true,
588
+ get: function() {
589
+ return isContentFormat;
590
+ }
591
+ });
592
+ Object.defineProperty(exports, "isReadOnlyContentFormat", {
593
+ enumerable: true,
594
+ get: function() {
595
+ return isReadOnlyContentFormat;
596
+ }
597
+ });
598
+ Object.defineProperty(exports, "isSourceContentFormat", {
599
+ enumerable: true,
600
+ get: function() {
601
+ return isSourceContentFormat;
602
+ }
603
+ });
604
+ Object.defineProperty(exports, "isTextFormatNode", {
605
+ enumerable: true,
606
+ get: function() {
607
+ return isTextFormatNode;
608
+ }
609
+ });
610
+ Object.defineProperty(exports, "resolveCompositionPlan", {
611
+ enumerable: true,
612
+ get: function() {
613
+ return resolveCompositionPlan;
614
+ }
615
+ });
616
+ Object.defineProperty(exports, "runCompositionPlan", {
617
+ enumerable: true,
618
+ get: function() {
619
+ return runCompositionPlan;
620
+ }
621
+ });
622
+ Object.defineProperty(exports, "shortestPath", {
623
+ enumerable: true,
624
+ get: function() {
625
+ return shortestPath;
626
+ }
627
+ });