js.documents 14.4.123 → 14.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/dist/{composition-plan-l6QPO4FX.d.ts → composition-plan-B1Nn2JCQ.d.ts} +10 -1
- package/dist/{composition-plan-CfvhXeOC.cjs → composition-plan-BgsXTscN.cjs} +19 -7
- package/dist/{composition-plan-DU9nPPN7.d.cts → composition-plan-Cofo9qPI.d.cts} +10 -1
- package/dist/{composition-plan-f0zaExUW.js → composition-plan-mRolIOZY.js} +19 -7
- package/dist/convert/composition-plan.cjs +1 -1
- package/dist/convert/composition-plan.d.cts +1 -1
- package/dist/convert/composition-plan.d.ts +1 -1
- package/dist/convert/composition-plan.js +1 -1
- package/dist/convert/composition-to-pdf.cjs +1 -1
- package/dist/convert/composition-to-pdf.d.cts +1 -1
- package/dist/convert/composition-to-pdf.d.ts +1 -1
- package/dist/convert/composition-to-pdf.js +1 -1
- package/dist/convert/composition.cjs +1 -1
- package/dist/convert/composition.d.cts +1 -1
- package/dist/convert/composition.d.ts +1 -1
- package/dist/convert/composition.js +1 -1
- package/dist/convert/from-package.cjs +1 -1
- package/dist/convert/from-package.js +1 -1
- package/dist/convert/from-pdf.cjs +10 -6
- package/dist/convert/from-pdf.d.cts +10 -0
- package/dist/convert/from-pdf.d.ts +10 -0
- package/dist/convert/from-pdf.js +11 -7
- package/dist/convert/local.cjs +1 -1
- package/dist/convert/local.js +1 -1
- package/dist/convert/pdf-package-tables.cjs +3 -1
- package/dist/convert/pdf-package-tables.js +3 -1
- package/dist/edit/ods/floating.cjs +5 -3
- package/dist/edit/ods/floating.js +5 -3
- package/dist/edit/pdf/editor.cjs +4 -1
- package/dist/edit/pdf/editor.d.cts +1 -1
- package/dist/edit/pdf/editor.d.ts +1 -1
- package/dist/edit/pdf/editor.js +4 -1
- package/dist/index.cjs +22 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/layout/reconstruct-presentations-prod.cjs +1 -1
- package/dist/layout/reconstruct-presentations-prod.js +1 -1
- package/dist/layout/reconstruct-tables.cjs +1 -1
- package/dist/layout/reconstruct-tables.js +1 -1
- package/dist/layout/reconstruct.cjs +1 -1
- package/dist/layout/reconstruct.js +1 -1
- package/dist/markdown/render.d.cts +2 -2
- package/dist/markdown/render.d.ts +2 -2
- package/dist/markdown/write.cjs +54 -1
- package/dist/markdown/write.d.cts +23 -2
- package/dist/markdown/write.d.ts +23 -2
- package/dist/markdown/write.js +53 -2
- package/dist/{reconstruct-presentations-prod-X315aBmI.cjs → reconstruct-presentations-prod-CA4no_aw.cjs} +13 -12
- package/dist/{reconstruct-presentations-prod-B5fkPiRZ.js → reconstruct-presentations-prod-CC8ct-5O.js} +13 -12
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -383,7 +383,25 @@ One subpath is a declared entry point in its own right: **`documents.js/read`**
|
|
|
383
383
|
import { pdfToMarkdown } from "documents.js/read";
|
|
384
384
|
```
|
|
385
385
|
|
|
386
|
-
It carries the ten `pdfTo*` conversions, `PdfToDocumentOptions`, `readDocumentMetadata` (with `ReadDocumentMetadataOptions`), `readNativeDocumentTree` (with `ReadNativeDocumentTreeOptions`), and `readContentDocument` (with `ReadContentDocumentOptions`) — identical functions to the root barrel's (the same forwarders, run through the composition engine's read half, and the same
|
|
386
|
+
It carries the ten `pdfTo*` conversions, `PdfToDocumentOptions`, `readDocumentMetadata` (with `ReadDocumentMetadataOptions`), `readNativeDocumentTree` (with `ReadNativeDocumentTreeOptions`), and `readContentDocument` (with `ReadContentDocumentOptions`) — identical functions to the root barrel's (the same forwarders, run through the composition engine's read half, and the same read-only dispatch: `src/codecs/read.ts`'s `CONTENT_READERS` for a content format, and pdf-codec's `readPdf` directly for pdf), never a forked behaviour; `convertDocument` and every X-to-PDF direction stay on the root barrel. `src/read-graph.test.ts` walks the entry's static import graph, follows `pdf-codec` specifiers through that package's real `exports` map into its source, and fails the build if the write path or any font asset becomes reachable.
|
|
387
|
+
|
|
388
|
+
### Converting a selection of a PDF's pages
|
|
389
|
+
|
|
390
|
+
The PDF-sourced entry points that produce content take a `pages` option: the `pdfTo*` conversions (`PdfToDocumentOptions.pages`), `convertDocument` with a pdf source (`UnifiedConversionOptions.pages`), and `readNativeDocumentTree`/`readContentDocument` (`ReadNativeDocumentTreeOptions.pages`). It is pdf-codec's `ReadPdfOptions.pages` threaded through: zero-based page-tree indices, a negative index counted from the end (`-1` is the last page), duplicates collapsed, the result in document order, and `PdfPageSelectionError` for an index naming no page. Two entry points never take it: `readDocumentMetadata` always reads with an empty selection, since metadata never depends on page content, so identifying a document reads no page at all; and `openPdf` always reads every page, since an editor holds a document to write back. `convertDocument` applies `pages` only when the source itself is pdf: a conversion from another format ignores it, including one whose route renders an intermediate pdf internally (docx to ods), because that pdf is not the caller's document.
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
import { pdfToMarkdown } from "documents.js/read";
|
|
394
|
+
|
|
395
|
+
const coverAndLastPage = pdfToMarkdown(pdfBytes, { pages: [0, 1, 2, -1] });
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
What a selection skips: the unselected pages' content streams are never fetched, decoded or interpreted, the fonts and images only those pages use are never resolved, and the source's embedded files are never decoded, so the result carries no attachments; a caller holding the `LayoutDocument` checks `pageCount` (set only on a page-selected read) before concluding the document has none (see pdf-codec's README for exactly what is and is not read). That is what lets a caller identify a document from its first pages, or read a code from its last page, inside a memory-capped runtime such as a Cloudflare Worker isolate, without paying for every page's content.
|
|
399
|
+
|
|
400
|
+
The output holds only the selected pages, and reconstruction sees only them, so a page can come out differently than in a full conversion. Heading detection measures text against the body size, taken as the most common text size across the pages read: a cover page read on its own, dominated by large title text, takes the title's size as its body, so the title becomes a paragraph rather than a heading. Reading the cover together with a few ordinary pages restores the document's real body size.
|
|
401
|
+
|
|
402
|
+
Markdown output labels each selected page with its original one-based page number, written as `<!-- page N -->` on its own line at the start of the page (`pageNumberMarker`), alongside the `<!-- page break -->` marker between pages that share a section, so a caller can tell which pages it got without re-deriving the selection. The label is output-only: reading markdown back keeps it as an ordinary HTML-comment paragraph, exactly as any other comment in a markdown source is kept. A full conversion writes no labels, so its output is unchanged. A caller composing the stages itself (`readPdf` with `pages`, `reconstructWordprocessing`, then `buildMarkdownText` or `renderContentDocumentToMarkdown`) gets the same labels by passing `pageNumbers: layout.pages.map((page, position) => sourcePageIndex(page, position) + 1)`; `buildMarkdownText` throws `MarkdownPageNumberCountError` when the count does not match the document's pages, and a non-wordprocessing document flattened by `renderContentDocumentToMarkdown` counts as a single page.
|
|
403
|
+
|
|
404
|
+
Every reconstructed node's frames name the page's index in the source PDF (the same index every destination and form widget names), which is why a page-selected conversion's reported `DocumentTree` carries no `pages` envelope: that array is indexed by frame page index, and a selection cannot fill it. Such a tree cannot be rebuilt to pdf either: `buildDocumentBytes(tree, "pdf")` needs that envelope and throws without it. A later stage's own page-addressing option, such as `page` for an svg target, counts within the selection. A page-selected `LayoutDocument` cannot be written back: `writePdf` refuses one with `PdfPartialDocumentError`. `PdfPageSelectionError`, `PdfPartialDocumentError` and `sourcePageIndex` are exported from the root barrel; the `documents.js/read` entry re-exports nothing (this package allows re-exports only in its root barrel), so a caller of that entry recognises a bad selection by the thrown error's `code` (`pdf/page-out-of-range` or `pdf/page-index-not-integer`), and resolves a page's source index as `page.index ?? position`.
|
|
387
405
|
|
|
388
406
|
### Reading and building xlsx content directly
|
|
389
407
|
|
|
@@ -821,8 +839,8 @@ The package is layered from generic primitives outward to the two conversion dir
|
|
|
821
839
|
- **`src/firebird/`** — Tier 3: gbak logical-backup reader. `reader.ts` (attribute framing + RLE decompression + XDR decoding), `schema.ts`/`data.ts` (table/row walking). No ratified spec — built against Firebird's own engine source.
|
|
822
840
|
- **`src/odb/`** — decoder-selection and pivot-mapping: `read.ts` routes to the right tier, `spreadsheet.ts`/`csv.ts` map to output formats. `odb/sql/` is the bounded SQL engine, `odb/formula/` is the rpt formula engine, `odb/report/` is the renderer, `odb/values.ts` is shared comparison/aggregation semantics.
|
|
823
841
|
- **`src/convert/`** — the composition layer: `convert.ts` (the named conversion functions and their option types), `composition.ts` (the pathfinder, the primitive registry, the bridge/fromPdf executors, and `convertDocumentFromPdf` — the read half of the engine), `composition-to-pdf.ts` (`executeToPdf`, the layout-engine registry, and the full `convertDocument` binding — the write half, split out so a read-only consumer never statically imports a renderer), `from-pdf.ts` (the `pdfTo*` family, `readDocumentMetadata`, `readNativeDocumentTree`, `readContentDocument`, and the `documents.js/read` entry), `codec.ts` (`z.codec()` pairs), `port.ts`/`local.ts` (the `DocumentConverter` port), `variant-bridges.ts` (cross-variant semantic transforms), and `from-package.ts` (`buildDocumentBytes`, which flattens once at the boundary). The tree ⇄ flat transform those construction sites call — `assembleTree`, `decompose`, `flattenTree`, `factorStyles` — is not implemented here: it lives in `document-schema.js`, which owns both encodings. `bijection.test.ts` is this package's own gate on it, re-running the three laws over the real corpus every reader, editor, and conversion here produces.
|
|
824
|
-
- **`src/codecs/`** — `DOCUMENT_FORMAT_CODECS`: every format's read/build capability as data, so `
|
|
825
|
-
- **`src/metadata
|
|
842
|
+
- **`src/codecs/`** — `DOCUMENT_FORMAT_CODECS`: every format's read/build capability as data, so `setDocumentMetadata`/`buildDocumentBytes` dispatch through one registry; its read halves live in `read.ts`, whose `CONTENT_READERS` `readDocumentMetadata` uses for content formats (it reads pdf through pdf-codec's `readPdf` directly, with no page selected).
|
|
843
|
+
- **`src/metadata/`**: cross-format metadata write via `DOCUMENT_FORMAT_CODECS`; the read side is `readDocumentMetadata` in `src/convert/from-pdf.ts`, which reads a content format through `CONTENT_READERS` and a pdf through `readPdf` with an empty page selection.
|
|
826
844
|
- **`src/package-codec.ts`** — `decodeDocumentPackage`/`encodeDocumentPackage`/`decodeOdbPackage`.
|
|
827
845
|
|
|
828
846
|
Dependency direction is downward and checkable. Twelve external dependencies each own a distinct concern: `ooxml.js` (docx/pptx/xlsx), `odf.js` (odt/ods/odp/odg), `document-schema.js` (shared schemas + port contracts), `pdf-codec` (PDF codec + text-layout/font primitives), `byte-codec` (byte/image utilities), `markdown-codec` (markdown), `rtf-codec` (rtf), `wpd-codec` (wpd, read-only), `doc-codec` (doc), `xls-codec` (xls), `ppt-codec` (ppt, through this package's own `src/ppt/` envelope adapter), `archive-codec` (the `[MS-CFB]` compound-file detection all three legacy binary codecs' own bytes schemas build on). No `PdfObject`/`PdfDict`/`PdfStream` type appears anywhere in this package.
|
|
@@ -33,6 +33,15 @@ interface UnifiedConversionOptions {
|
|
|
33
33
|
readonly page?: number;
|
|
34
34
|
readonly onSvgDiagnostic?: SvgDiagnosticSink;
|
|
35
35
|
readonly clock?: ClockPort;
|
|
36
|
+
/**
|
|
37
|
+
* The pages of a pdf source to convert, as pdf-codec's `ReadPdfOptions.pages` reads them: zero-based page-tree indices, a negative index counted from the end, duplicates collapsed, the result in document order, and an index naming no page throwing `PdfPageSelectionError`. Only the plan's first hop receives it, and only when the conversion's source is pdf: a conversion from any other format ignores it, including one whose route renders an intermediate pdf internally (docx to ods goes through toPdf then fromPdf), since that pdf is not the caller's document. The unselected pages' content streams, the fonts and images only they use, and the source's embedded files are never read (see `ReadPdfOptions.pages` for exactly what is and is not skipped).
|
|
38
|
+
*
|
|
39
|
+
* The output holds only those pages. A markdown target labels each with its original one-based page number (`<!-- page 7 -->` at the start of the page, beside the usual `<!-- page break -->` between pages), so the text says which pages it holds. A page-addressing option of a later stage, such as `page` for an svg target, counts within the selection. Reconstruction infers from the selected pages alone, so a page can reconstruct differently than it would in a full conversion: the body text size heading detection compares against is the most common size across the selection, which on a cover page dominated by large title text is the title's own size, leaving the title a paragraph rather than a heading. The DocumentTree `onDocument` reports carries no `pages` envelope for a page-selected conversion: its frames name source page indices, which an envelope holding only the selected pages could not be indexed by.
|
|
40
|
+
*/
|
|
41
|
+
readonly pages?: readonly number[];
|
|
42
|
+
}
|
|
43
|
+
interface TextBuildContext {
|
|
44
|
+
readonly pageNumbers?: readonly number[];
|
|
36
45
|
}
|
|
37
46
|
type ContentFormat = "docx" | "pptx" | "xlsx" | "odt" | "odp" | "ods" | "odg" | "svg" | "csv" | "markdown" | "rtf" | "doc" | "xls" | "ppt" | "epub";
|
|
38
47
|
declare const CONTENT_FORMATS: readonly ContentFormat[];
|
|
@@ -51,7 +60,7 @@ interface TextFormatNode {
|
|
|
51
60
|
readonly family: "markdown" | "csv" | "svg" | "rtf" | "doc" | "xls" | "ppt" | "epub";
|
|
52
61
|
readonly decode: (bytes: Uint8Array<ArrayBuffer>) => string;
|
|
53
62
|
readonly read: (text: string, options?: UnifiedConversionOptions) => ContentDocument;
|
|
54
|
-
readonly build: (content: ContentDocument, options?: UnifiedConversionOptions) => string;
|
|
63
|
+
readonly build: (content: ContentDocument, options?: UnifiedConversionOptions & TextBuildContext) => string;
|
|
55
64
|
readonly encode: (text: string) => Uint8Array<ArrayBuffer>;
|
|
56
65
|
readonly hasSourcePackage: false;
|
|
57
66
|
}
|
|
@@ -23,7 +23,7 @@ const require_csv_write = require("./csv/write.cjs");
|
|
|
23
23
|
const require_read$1 = require("./read-CahCZMwG.cjs");
|
|
24
24
|
const require_svg_write = require("./svg/write.cjs");
|
|
25
25
|
const require_ports_abort = require("./ports/abort.cjs");
|
|
26
|
-
const require_reconstruct_presentations_prod = require("./reconstruct-presentations-prod-
|
|
26
|
+
const require_reconstruct_presentations_prod = require("./reconstruct-presentations-prod-CA4no_aw.cjs");
|
|
27
27
|
const require_convert_pdf_package_tables = require("./convert/pdf-package-tables.cjs");
|
|
28
28
|
const require_convert_variant_bridges = require("./convert/variant-bridges.cjs");
|
|
29
29
|
const require_convert_capability = require("./convert/capability.cjs");
|
|
@@ -34,6 +34,7 @@ let doc_codec = require("doc-codec");
|
|
|
34
34
|
let xls_codec = require("xls-codec");
|
|
35
35
|
let rtf_codec = require("rtf-codec");
|
|
36
36
|
let epub_codec = require("epub-codec");
|
|
37
|
+
let pdf_codec_layout = require("pdf-codec/layout");
|
|
37
38
|
require("markdown-codec");
|
|
38
39
|
let wpd_codec = require("wpd-codec");
|
|
39
40
|
let pdf_codec_read = require("pdf-codec/read");
|
|
@@ -127,7 +128,7 @@ const FORMAT_NODES = {
|
|
|
127
128
|
signal: options?.signal,
|
|
128
129
|
images: options?.images
|
|
129
130
|
}),
|
|
130
|
-
build: (content) => require_markdown_write.buildMarkdownText(content),
|
|
131
|
+
build: (content, options) => require_markdown_write.buildMarkdownText(content, { pageNumbers: options?.pageNumbers }),
|
|
131
132
|
encode: (text) => require_markdown_text.encodeMarkdownText(text),
|
|
132
133
|
hasSourcePackage: false
|
|
133
134
|
},
|
|
@@ -335,23 +336,31 @@ function executeBridge(source, target, bytes, options) {
|
|
|
335
336
|
options?.onDocument?.((0, document_schema_js.assembleTree)(buildContent));
|
|
336
337
|
return out;
|
|
337
338
|
}
|
|
339
|
+
function layoutPageNumbers(layout) {
|
|
340
|
+
return layout.pages.map((page, position) => (0, pdf_codec_layout.sourcePageIndex)(page, position) + 1);
|
|
341
|
+
}
|
|
338
342
|
function executeFromPdf(target, bytes, options) {
|
|
339
343
|
const node = FORMAT_NODES[target];
|
|
340
344
|
const layout = (0, pdf_codec_read.readPdf)(bytes, {
|
|
341
345
|
signal: options?.signal,
|
|
342
|
-
sink: options?.sink
|
|
346
|
+
sink: options?.sink,
|
|
347
|
+
pages: options?.pages
|
|
343
348
|
});
|
|
344
349
|
const content = RECONSTRUCTORS[node.variant](layout, {
|
|
345
350
|
signal: options?.signal,
|
|
346
351
|
onCellTypeInference: options?.onCellTypeInference
|
|
347
352
|
});
|
|
348
|
-
const
|
|
353
|
+
const selected = options?.pages !== void 0;
|
|
354
|
+
const pages = selected ? void 0 : layout.pages.map((page) => ({
|
|
349
355
|
widthPt: page.widthPt,
|
|
350
356
|
heightPt: page.heightPt
|
|
351
357
|
}));
|
|
352
358
|
let out;
|
|
353
359
|
if (isTextFormatNode(node)) {
|
|
354
|
-
const text = node.build(content,
|
|
360
|
+
const text = node.build(content, {
|
|
361
|
+
...options,
|
|
362
|
+
pageNumbers: selected ? layoutPageNumbers(layout) : void 0
|
|
363
|
+
});
|
|
355
364
|
out = node.encode(text);
|
|
356
365
|
} else {
|
|
357
366
|
const pkg = node.build(content);
|
|
@@ -367,9 +376,12 @@ function runCompositionPlan(plan, bytes, options, executors) {
|
|
|
367
376
|
for (let i = 0; i < plan.hops.length; i++) {
|
|
368
377
|
const hop = plan.hops[i];
|
|
369
378
|
if (hop === void 0) throw new Error("runCompositionPlan: resolveCompositionPlan returned a malformed hop");
|
|
370
|
-
const
|
|
379
|
+
const isLastHop = i === plan.hops.length - 1;
|
|
380
|
+
const readsCallerPdf = i === 0 && hop.from === "pdf";
|
|
381
|
+
const hopOptions = options === void 0 ? void 0 : {
|
|
371
382
|
...options,
|
|
372
|
-
onDocument: void 0
|
|
383
|
+
onDocument: isLastHop ? options.onDocument : void 0,
|
|
384
|
+
pages: readsCallerPdf ? options.pages : void 0
|
|
373
385
|
};
|
|
374
386
|
if (hop.executor === "toPdf") {
|
|
375
387
|
if (!isSourceContentFormat(hop.from)) throw new Error(`runCompositionPlan: toPdf source '${hop.from}' is not a content format`);
|
|
@@ -33,6 +33,15 @@ interface UnifiedConversionOptions {
|
|
|
33
33
|
readonly page?: number;
|
|
34
34
|
readonly onSvgDiagnostic?: SvgDiagnosticSink;
|
|
35
35
|
readonly clock?: ClockPort;
|
|
36
|
+
/**
|
|
37
|
+
* The pages of a pdf source to convert, as pdf-codec's `ReadPdfOptions.pages` reads them: zero-based page-tree indices, a negative index counted from the end, duplicates collapsed, the result in document order, and an index naming no page throwing `PdfPageSelectionError`. Only the plan's first hop receives it, and only when the conversion's source is pdf: a conversion from any other format ignores it, including one whose route renders an intermediate pdf internally (docx to ods goes through toPdf then fromPdf), since that pdf is not the caller's document. The unselected pages' content streams, the fonts and images only they use, and the source's embedded files are never read (see `ReadPdfOptions.pages` for exactly what is and is not skipped).
|
|
38
|
+
*
|
|
39
|
+
* The output holds only those pages. A markdown target labels each with its original one-based page number (`<!-- page 7 -->` at the start of the page, beside the usual `<!-- page break -->` between pages), so the text says which pages it holds. A page-addressing option of a later stage, such as `page` for an svg target, counts within the selection. Reconstruction infers from the selected pages alone, so a page can reconstruct differently than it would in a full conversion: the body text size heading detection compares against is the most common size across the selection, which on a cover page dominated by large title text is the title's own size, leaving the title a paragraph rather than a heading. The DocumentTree `onDocument` reports carries no `pages` envelope for a page-selected conversion: its frames name source page indices, which an envelope holding only the selected pages could not be indexed by.
|
|
40
|
+
*/
|
|
41
|
+
readonly pages?: readonly number[];
|
|
42
|
+
}
|
|
43
|
+
interface TextBuildContext {
|
|
44
|
+
readonly pageNumbers?: readonly number[];
|
|
36
45
|
}
|
|
37
46
|
type ContentFormat = "docx" | "pptx" | "xlsx" | "odt" | "odp" | "ods" | "odg" | "svg" | "csv" | "markdown" | "rtf" | "doc" | "xls" | "ppt" | "epub";
|
|
38
47
|
declare const CONTENT_FORMATS: readonly ContentFormat[];
|
|
@@ -51,7 +60,7 @@ interface TextFormatNode {
|
|
|
51
60
|
readonly family: "markdown" | "csv" | "svg" | "rtf" | "doc" | "xls" | "ppt" | "epub";
|
|
52
61
|
readonly decode: (bytes: Uint8Array<ArrayBuffer>) => string;
|
|
53
62
|
readonly read: (text: string, options?: UnifiedConversionOptions) => ContentDocument;
|
|
54
|
-
readonly build: (content: ContentDocument, options?: UnifiedConversionOptions) => string;
|
|
63
|
+
readonly build: (content: ContentDocument, options?: UnifiedConversionOptions & TextBuildContext) => string;
|
|
55
64
|
readonly encode: (text: string) => Uint8Array<ArrayBuffer>;
|
|
56
65
|
readonly hasSourcePackage: false;
|
|
57
66
|
}
|
|
@@ -23,7 +23,7 @@ import { buildCsvText } from "./csv/write.js";
|
|
|
23
23
|
import { i as readSvgContent } from "./read-BSH--XB4.js";
|
|
24
24
|
import { buildSvgText } from "./svg/write.js";
|
|
25
25
|
import { throwIfAborted } from "./ports/abort.js";
|
|
26
|
-
import { _ as reconstructWordprocessing, g as reconstructSpreadsheet, i as reconstructPresentation, r as reconstructDrawing } from "./reconstruct-presentations-prod-
|
|
26
|
+
import { _ as reconstructWordprocessing, g as reconstructSpreadsheet, i as reconstructPresentation, r as reconstructDrawing } from "./reconstruct-presentations-prod-CC8ct-5O.js";
|
|
27
27
|
import { stampPdfPackageTables } from "./convert/pdf-package-tables.js";
|
|
28
28
|
import { drawingToPresentation, presentationToDrawing, presentationToWordprocessing, spreadsheetToWordprocessing, wordprocessingToPresentation } from "./convert/variant-bridges.js";
|
|
29
29
|
import { UnsupportedConversionError } from "./convert/capability.js";
|
|
@@ -34,6 +34,7 @@ import { readDocContent, writeDocContent } from "doc-codec";
|
|
|
34
34
|
import { readXlsContent, writeXlsContent } from "xls-codec";
|
|
35
35
|
import { readRtfContent, rtfBytesFromLatin1, writeRtfContent } from "rtf-codec";
|
|
36
36
|
import { readEpubContent, writeEpubContent } from "epub-codec";
|
|
37
|
+
import { sourcePageIndex } from "pdf-codec/layout";
|
|
37
38
|
import "markdown-codec";
|
|
38
39
|
import { readWpdContent } from "wpd-codec";
|
|
39
40
|
import { readPdf } from "pdf-codec/read";
|
|
@@ -127,7 +128,7 @@ const FORMAT_NODES = {
|
|
|
127
128
|
signal: options?.signal,
|
|
128
129
|
images: options?.images
|
|
129
130
|
}),
|
|
130
|
-
build: (content) => buildMarkdownText(content),
|
|
131
|
+
build: (content, options) => buildMarkdownText(content, { pageNumbers: options?.pageNumbers }),
|
|
131
132
|
encode: (text) => encodeMarkdownText(text),
|
|
132
133
|
hasSourcePackage: false
|
|
133
134
|
},
|
|
@@ -335,23 +336,31 @@ function executeBridge(source, target, bytes, options) {
|
|
|
335
336
|
options?.onDocument?.(assembleTree(buildContent));
|
|
336
337
|
return out;
|
|
337
338
|
}
|
|
339
|
+
function layoutPageNumbers(layout) {
|
|
340
|
+
return layout.pages.map((page, position) => sourcePageIndex(page, position) + 1);
|
|
341
|
+
}
|
|
338
342
|
function executeFromPdf(target, bytes, options) {
|
|
339
343
|
const node = FORMAT_NODES[target];
|
|
340
344
|
const layout = readPdf(bytes, {
|
|
341
345
|
signal: options?.signal,
|
|
342
|
-
sink: options?.sink
|
|
346
|
+
sink: options?.sink,
|
|
347
|
+
pages: options?.pages
|
|
343
348
|
});
|
|
344
349
|
const content = RECONSTRUCTORS[node.variant](layout, {
|
|
345
350
|
signal: options?.signal,
|
|
346
351
|
onCellTypeInference: options?.onCellTypeInference
|
|
347
352
|
});
|
|
348
|
-
const
|
|
353
|
+
const selected = options?.pages !== void 0;
|
|
354
|
+
const pages = selected ? void 0 : layout.pages.map((page) => ({
|
|
349
355
|
widthPt: page.widthPt,
|
|
350
356
|
heightPt: page.heightPt
|
|
351
357
|
}));
|
|
352
358
|
let out;
|
|
353
359
|
if (isTextFormatNode(node)) {
|
|
354
|
-
const text = node.build(content,
|
|
360
|
+
const text = node.build(content, {
|
|
361
|
+
...options,
|
|
362
|
+
pageNumbers: selected ? layoutPageNumbers(layout) : void 0
|
|
363
|
+
});
|
|
355
364
|
out = node.encode(text);
|
|
356
365
|
} else {
|
|
357
366
|
const pkg = node.build(content);
|
|
@@ -367,9 +376,12 @@ function runCompositionPlan(plan, bytes, options, executors) {
|
|
|
367
376
|
for (let i = 0; i < plan.hops.length; i++) {
|
|
368
377
|
const hop = plan.hops[i];
|
|
369
378
|
if (hop === void 0) throw new Error("runCompositionPlan: resolveCompositionPlan returned a malformed hop");
|
|
370
|
-
const
|
|
379
|
+
const isLastHop = i === plan.hops.length - 1;
|
|
380
|
+
const readsCallerPdf = i === 0 && hop.from === "pdf";
|
|
381
|
+
const hopOptions = options === void 0 ? void 0 : {
|
|
371
382
|
...options,
|
|
372
|
-
onDocument: void 0
|
|
383
|
+
onDocument: isLastHop ? options.onDocument : void 0,
|
|
384
|
+
pages: readsCallerPdf ? options.pages : void 0
|
|
373
385
|
};
|
|
374
386
|
if (hop.executor === "toPdf") {
|
|
375
387
|
if (!isSourceContentFormat(hop.from)) throw new Error(`runCompositionPlan: toPdf source '${hop.from}' is not a content format`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_composition_plan = require("../composition-plan-
|
|
2
|
+
const require_composition_plan = require("../composition-plan-BgsXTscN.cjs");
|
|
3
3
|
exports.buildCompositionGraph = require_composition_plan.buildCompositionGraph;
|
|
4
4
|
exports.isContentFormat = require_composition_plan.isContentFormat;
|
|
5
5
|
exports.isSourceContentFormat = require_composition_plan.isSourceContentFormat;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as buildCompositionGraph, c as resolveCompositionPlan, i as HopExecutor, l as shortestPath, n as ConversionPlan, o as isContentFormat, r as GraphEdge, s as isSourceContentFormat, t as CompositionHop } from "../composition-plan-
|
|
1
|
+
import { a as buildCompositionGraph, c as resolveCompositionPlan, i as HopExecutor, l as shortestPath, n as ConversionPlan, o as isContentFormat, r as GraphEdge, s as isSourceContentFormat, t as CompositionHop } from "../composition-plan-Cofo9qPI.cjs";
|
|
2
2
|
export { CompositionHop, ConversionPlan, GraphEdge, HopExecutor, buildCompositionGraph, isContentFormat, isSourceContentFormat, resolveCompositionPlan, shortestPath };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as buildCompositionGraph, c as resolveCompositionPlan, i as HopExecutor, l as shortestPath, n as ConversionPlan, o as isContentFormat, r as GraphEdge, s as isSourceContentFormat, t as CompositionHop } from "../composition-plan-
|
|
1
|
+
import { a as buildCompositionGraph, c as resolveCompositionPlan, i as HopExecutor, l as shortestPath, n as ConversionPlan, o as isContentFormat, r as GraphEdge, s as isSourceContentFormat, t as CompositionHop } from "../composition-plan-B1Nn2JCQ.js";
|
|
2
2
|
export { CompositionHop, ConversionPlan, GraphEdge, HopExecutor, buildCompositionGraph, isContentFormat, isSourceContentFormat, resolveCompositionPlan, shortestPath };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as shortestPath, i as resolveCompositionPlan, n as isContentFormat, r as isSourceContentFormat, t as buildCompositionGraph } from "../composition-plan-
|
|
1
|
+
import { a as shortestPath, i as resolveCompositionPlan, n as isContentFormat, r as isSourceContentFormat, t as buildCompositionGraph } from "../composition-plan-mRolIOZY.js";
|
|
2
2
|
export { buildCompositionGraph, isContentFormat, isSourceContentFormat, resolveCompositionPlan, shortestPath };
|
|
@@ -7,7 +7,7 @@ const require_ports_abort = require("../ports/abort.cjs");
|
|
|
7
7
|
const require_sheets = require("../sheets-BQCpNXsE.cjs");
|
|
8
8
|
const require_layout_drawing = require("../layout/drawing.cjs");
|
|
9
9
|
const require_convert_capability = require("./capability.cjs");
|
|
10
|
-
const require_composition_plan = require("../composition-plan-
|
|
10
|
+
const require_composition_plan = require("../composition-plan-BgsXTscN.cjs");
|
|
11
11
|
let document_schema_js = require("document-schema.js");
|
|
12
12
|
let pdf_codec = require("pdf-codec");
|
|
13
13
|
//#region src/convert/composition-to-pdf.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DocumentFormat } from "./port.cjs";
|
|
2
|
-
import { S as SourceContentFormat, T as UnifiedConversionOptions } from "../composition-plan-
|
|
2
|
+
import { S as SourceContentFormat, T as UnifiedConversionOptions } from "../composition-plan-Cofo9qPI.cjs";
|
|
3
3
|
//#region src/convert/composition-to-pdf.d.ts
|
|
4
4
|
declare function executeToPdf(format: SourceContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
|
|
5
5
|
declare function convertDocument(source: DocumentFormat, target: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DocumentFormat } from "./port.js";
|
|
2
|
-
import { S as SourceContentFormat, T as UnifiedConversionOptions } from "../composition-plan-
|
|
2
|
+
import { S as SourceContentFormat, T as UnifiedConversionOptions } from "../composition-plan-B1Nn2JCQ.js";
|
|
3
3
|
//#region src/convert/composition-to-pdf.d.ts
|
|
4
4
|
declare function executeToPdf(format: SourceContentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
|
|
5
5
|
declare function convertDocument(source: DocumentFormat, target: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, options?: UnifiedConversionOptions): Uint8Array<ArrayBuffer>;
|
|
@@ -6,7 +6,7 @@ import { throwIfAborted } from "../ports/abort.js";
|
|
|
6
6
|
import { l as convertSpreadsheetToLayout } from "../sheets-DWDvGN-g.js";
|
|
7
7
|
import { convertDrawingToLayout } from "../layout/drawing.js";
|
|
8
8
|
import { UnsupportedConversionError } from "./capability.js";
|
|
9
|
-
import { _ as executeFromPdf, b as runCompositionPlan, c as LAYOUT_CAPABLE, d as READ_ONLY_FORMAT_NODES, g as executeBridge, i as resolveCompositionPlan, s as FORMAT_NODES, v as isReadOnlyContentFormat, y as isTextFormatNode } from "../composition-plan-
|
|
9
|
+
import { _ as executeFromPdf, b as runCompositionPlan, c as LAYOUT_CAPABLE, d as READ_ONLY_FORMAT_NODES, g as executeBridge, i as resolveCompositionPlan, s as FORMAT_NODES, v as isReadOnlyContentFormat, y as isTextFormatNode } from "../composition-plan-mRolIOZY.js";
|
|
10
10
|
import { assembleTree } from "document-schema.js";
|
|
11
11
|
import { createFontMeasurer, createFontRegistry, loadMathFont, writePdf } from "pdf-codec";
|
|
12
12
|
//#region src/convert/composition-to-pdf.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_composition_plan = require("../composition-plan-
|
|
2
|
+
const require_composition_plan = require("../composition-plan-BgsXTscN.cjs");
|
|
3
3
|
exports.CONTENT_FORMATS = require_composition_plan.CONTENT_FORMATS;
|
|
4
4
|
exports.FORMAT_NODES = require_composition_plan.FORMAT_NODES;
|
|
5
5
|
exports.LAYOUT_CAPABLE = require_composition_plan.LAYOUT_CAPABLE;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as isTextFormatNode, C as THROUGH_PDF_EDGE_COST, D as executeBridge, E as convertDocumentFromPdf, O as executeFromPdf, S as SourceContentFormat, T as UnifiedConversionOptions, _ as READ_ONLY_CONTENT_FORMATS, b as ReadOnlyContentFormat, d as CompositionExecutorBinding, f as ContentFormat, g as MAX_CONVERSION_PATH_NODES, h as LAYOUT_CAPABLE, j as runCompositionPlan, k as isReadOnlyContentFormat, m as FormatNode, p as FORMAT_NODES, u as CONTENT_FORMATS, v as READ_ONLY_FORMAT_NODES, w as TRANSFORMS, x as ReadOnlyFormatNode, y as RECONSTRUCTORS } from "../composition-plan-
|
|
1
|
+
import { A as isTextFormatNode, C as THROUGH_PDF_EDGE_COST, D as executeBridge, E as convertDocumentFromPdf, O as executeFromPdf, S as SourceContentFormat, T as UnifiedConversionOptions, _ as READ_ONLY_CONTENT_FORMATS, b as ReadOnlyContentFormat, d as CompositionExecutorBinding, f as ContentFormat, g as MAX_CONVERSION_PATH_NODES, h as LAYOUT_CAPABLE, j as runCompositionPlan, k as isReadOnlyContentFormat, m as FormatNode, p as FORMAT_NODES, u as CONTENT_FORMATS, v as READ_ONLY_FORMAT_NODES, w as TRANSFORMS, x as ReadOnlyFormatNode, y as RECONSTRUCTORS } from "../composition-plan-Cofo9qPI.cjs";
|
|
2
2
|
export { CONTENT_FORMATS, CompositionExecutorBinding, ContentFormat, FORMAT_NODES, FormatNode, LAYOUT_CAPABLE, MAX_CONVERSION_PATH_NODES, READ_ONLY_CONTENT_FORMATS, READ_ONLY_FORMAT_NODES, RECONSTRUCTORS, ReadOnlyContentFormat, ReadOnlyFormatNode, SourceContentFormat, THROUGH_PDF_EDGE_COST, TRANSFORMS, UnifiedConversionOptions, convertDocumentFromPdf, executeBridge, executeFromPdf, isReadOnlyContentFormat, isTextFormatNode, runCompositionPlan };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as isTextFormatNode, C as THROUGH_PDF_EDGE_COST, D as executeBridge, E as convertDocumentFromPdf, O as executeFromPdf, S as SourceContentFormat, T as UnifiedConversionOptions, _ as READ_ONLY_CONTENT_FORMATS, b as ReadOnlyContentFormat, d as CompositionExecutorBinding, f as ContentFormat, g as MAX_CONVERSION_PATH_NODES, h as LAYOUT_CAPABLE, j as runCompositionPlan, k as isReadOnlyContentFormat, m as FormatNode, p as FORMAT_NODES, u as CONTENT_FORMATS, v as READ_ONLY_FORMAT_NODES, w as TRANSFORMS, x as ReadOnlyFormatNode, y as RECONSTRUCTORS } from "../composition-plan-
|
|
1
|
+
import { A as isTextFormatNode, C as THROUGH_PDF_EDGE_COST, D as executeBridge, E as convertDocumentFromPdf, O as executeFromPdf, S as SourceContentFormat, T as UnifiedConversionOptions, _ as READ_ONLY_CONTENT_FORMATS, b as ReadOnlyContentFormat, d as CompositionExecutorBinding, f as ContentFormat, g as MAX_CONVERSION_PATH_NODES, h as LAYOUT_CAPABLE, j as runCompositionPlan, k as isReadOnlyContentFormat, m as FormatNode, p as FORMAT_NODES, u as CONTENT_FORMATS, v as READ_ONLY_FORMAT_NODES, w as TRANSFORMS, x as ReadOnlyFormatNode, y as RECONSTRUCTORS } from "../composition-plan-B1Nn2JCQ.js";
|
|
2
2
|
export { CONTENT_FORMATS, CompositionExecutorBinding, ContentFormat, FORMAT_NODES, FormatNode, LAYOUT_CAPABLE, MAX_CONVERSION_PATH_NODES, READ_ONLY_CONTENT_FORMATS, READ_ONLY_FORMAT_NODES, RECONSTRUCTORS, ReadOnlyContentFormat, ReadOnlyFormatNode, SourceContentFormat, THROUGH_PDF_EDGE_COST, TRANSFORMS, UnifiedConversionOptions, convertDocumentFromPdf, executeBridge, executeFromPdf, isReadOnlyContentFormat, isTextFormatNode, runCompositionPlan };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as executeFromPdf, b as runCompositionPlan, c as LAYOUT_CAPABLE, d as READ_ONLY_FORMAT_NODES, f as RECONSTRUCTORS, g as executeBridge, h as convertDocumentFromPdf, l as MAX_CONVERSION_PATH_NODES, m as TRANSFORMS, o as CONTENT_FORMATS, p as THROUGH_PDF_EDGE_COST, s as FORMAT_NODES, u as READ_ONLY_CONTENT_FORMATS, v as isReadOnlyContentFormat, y as isTextFormatNode } from "../composition-plan-
|
|
1
|
+
import { _ as executeFromPdf, b as runCompositionPlan, c as LAYOUT_CAPABLE, d as READ_ONLY_FORMAT_NODES, f as RECONSTRUCTORS, g as executeBridge, h as convertDocumentFromPdf, l as MAX_CONVERSION_PATH_NODES, m as TRANSFORMS, o as CONTENT_FORMATS, p as THROUGH_PDF_EDGE_COST, s as FORMAT_NODES, u as READ_ONLY_CONTENT_FORMATS, v as isReadOnlyContentFormat, y as isTextFormatNode } from "../composition-plan-mRolIOZY.js";
|
|
2
2
|
export { CONTENT_FORMATS, FORMAT_NODES, LAYOUT_CAPABLE, MAX_CONVERSION_PATH_NODES, READ_ONLY_CONTENT_FORMATS, READ_ONLY_FORMAT_NODES, RECONSTRUCTORS, THROUGH_PDF_EDGE_COST, TRANSFORMS, convertDocumentFromPdf, executeBridge, executeFromPdf, isReadOnlyContentFormat, isTextFormatNode, runCompositionPlan };
|
|
@@ -15,7 +15,7 @@ let pdf_codec = require("pdf-codec");
|
|
|
15
15
|
//#region src/convert/from-package.ts
|
|
16
16
|
function buildDocumentBytes(pkg, target) {
|
|
17
17
|
if (target === "pdf") {
|
|
18
|
-
if (pkg.pages === void 0) throw new Error("this DocumentTree has no pages
|
|
18
|
+
if (pkg.pages === void 0) throw new Error("this DocumentTree has no pages, so 'pdf' is not a reachable target from it: only a package dumped from a <format>-to-pdf conversion or a full pdf-to-<format> conversion carries them. A bridge conversion's own dump (e.g. odt-to-docx) never does, and neither does a page-selected pdf-to-<format> conversion's, whose frames name source page indices a pages array of only the selection could not be indexed by");
|
|
19
19
|
const { document: layout, formulas, fonts } = packageToLayout(pkg);
|
|
20
20
|
return (0, pdf_codec.writePdf)(layout, formulas.length > 0 ? {
|
|
21
21
|
formulas,
|
|
@@ -14,7 +14,7 @@ import { LAYOUT_FORMAT_VERSION, createFontMeasurer, createFontRegistry, loadMath
|
|
|
14
14
|
//#region src/convert/from-package.ts
|
|
15
15
|
function buildDocumentBytes(pkg, target) {
|
|
16
16
|
if (target === "pdf") {
|
|
17
|
-
if (pkg.pages === void 0) throw new Error("this DocumentTree has no pages
|
|
17
|
+
if (pkg.pages === void 0) throw new Error("this DocumentTree has no pages, so 'pdf' is not a reachable target from it: only a package dumped from a <format>-to-pdf conversion or a full pdf-to-<format> conversion carries them. A bridge conversion's own dump (e.g. odt-to-docx) never does, and neither does a page-selected pdf-to-<format> conversion's, whose frames name source page indices a pages array of only the selection could not be indexed by");
|
|
18
18
|
const { document: layout, formulas, fonts } = packageToLayout(pkg);
|
|
19
19
|
return writePdf(layout, formulas.length > 0 ? {
|
|
20
20
|
formulas,
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_reconstruct_presentations_prod = require("../reconstruct-presentations-prod-
|
|
2
|
+
const require_reconstruct_presentations_prod = require("../reconstruct-presentations-prod-CA4no_aw.cjs");
|
|
3
3
|
const require_convert_pdf_package_tables = require("./pdf-package-tables.cjs");
|
|
4
|
-
const require_composition_plan = require("../composition-plan-
|
|
4
|
+
const require_composition_plan = require("../composition-plan-BgsXTscN.cjs");
|
|
5
5
|
const require_codecs_read = require("../codecs/read.cjs");
|
|
6
6
|
let document_schema_js = require("document-schema.js");
|
|
7
7
|
let pdf_codec_read = require("pdf-codec/read");
|
|
8
8
|
//#region src/convert/from-pdf.ts
|
|
9
9
|
function readDocumentMetadata(format, bytes, options) {
|
|
10
|
-
if (format === "pdf") return
|
|
10
|
+
if (format === "pdf") return (0, pdf_codec_read.readPdf)(bytes, {
|
|
11
|
+
signal: options?.signal,
|
|
12
|
+
pages: []
|
|
13
|
+
}).metadata;
|
|
11
14
|
return require_codecs_read.CONTENT_READERS[format](bytes, { signal: options?.signal }).metadata;
|
|
12
15
|
}
|
|
13
16
|
function readNativeContent(format, bytes, options) {
|
|
14
17
|
if (format === "pdf") {
|
|
15
18
|
const layout = (0, pdf_codec_read.readPdf)(bytes, {
|
|
16
19
|
signal: options?.signal,
|
|
17
|
-
sink: options?.sink
|
|
20
|
+
sink: options?.sink,
|
|
21
|
+
pages: options?.pages
|
|
18
22
|
});
|
|
19
23
|
return {
|
|
20
24
|
content: require_reconstruct_presentations_prod.reconstructWordprocessing(layout, { signal: options?.signal }),
|
|
@@ -29,10 +33,10 @@ function readNativeContent(format, bytes, options) {
|
|
|
29
33
|
function readNativeDocumentTree(format, bytes, options) {
|
|
30
34
|
const { content, layout } = readNativeContent(format, bytes, options);
|
|
31
35
|
if (layout !== void 0) {
|
|
32
|
-
const pages = layout.pages.map((page) => ({
|
|
36
|
+
const pages = options?.pages === void 0 ? layout.pages.map((page) => ({
|
|
33
37
|
widthPt: page.widthPt,
|
|
34
38
|
heightPt: page.heightPt
|
|
35
|
-
}));
|
|
39
|
+
})) : void 0;
|
|
36
40
|
const reported = (0, document_schema_js.assembleTree)(content, pages);
|
|
37
41
|
require_convert_pdf_package_tables.stampPdfPackageTables(reported, layout);
|
|
38
42
|
return reported;
|
|
@@ -12,6 +12,10 @@ interface ReadNativeDocumentTreeOptions {
|
|
|
12
12
|
readonly signal?: AbortSignal;
|
|
13
13
|
readonly images?: MarkdownImageResolver;
|
|
14
14
|
readonly sink?: PdfDiagnosticSink;
|
|
15
|
+
/**
|
|
16
|
+
* The pages of a pdf source to read, exactly as UnifiedConversionOptions.pages describes them (zero-based, negative from the end, document order, `PdfPageSelectionError` for an index naming no page). Consulted only for a pdf source, since no other format's reader has pages to select. The unselected pages' content streams, the fonts and images only they use, and the source's embedded files are never read, and the selected pages are reconstructed from themselves alone (see PdfToDocumentOptions.pages for how that can change a cover page's headings). Every frame in the result names the page's index in the source PDF, so a DocumentTree read this way carries no `pages` envelope: that array is indexed by those source indices and a selection cannot fill it.
|
|
17
|
+
*/
|
|
18
|
+
readonly pages?: readonly number[];
|
|
15
19
|
}
|
|
16
20
|
type ReadContentDocumentOptions = ReadNativeDocumentTreeOptions;
|
|
17
21
|
declare function readNativeDocumentTree(format: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, options?: ReadNativeDocumentTreeOptions): DocumentTree;
|
|
@@ -19,6 +23,12 @@ declare function readContentDocument(format: DocumentFormat, bytes: Uint8Array<A
|
|
|
19
23
|
interface PdfToDocumentOptions {
|
|
20
24
|
readonly signal?: AbortSignal;
|
|
21
25
|
readonly sink?: PdfDiagnosticSink;
|
|
26
|
+
/**
|
|
27
|
+
* The pages to convert, exactly as UnifiedConversionOptions.pages describes them: zero-based page-tree indices, a negative index counted from the end, duplicates collapsed, document order, and `PdfPageSelectionError` for an index naming no page. The unselected pages' content streams, the fonts and images only they use, and the source's embedded files are never read. pdfToMarkdown labels each page it writes with its original one-based page number (`<!-- page 7 -->`), so the text says which pages it holds.
|
|
28
|
+
*
|
|
29
|
+
* Reconstruction sees only the selected pages, so a page can come out differently than it would in a full conversion. Heading detection measures text against the body size, taken as the most common size across the pages read: a cover page read on its own, dominated by large title text, takes the title's size as its body, and the title is then a paragraph rather than a heading. Reading the cover together with a few ordinary pages restores the document's real body size.
|
|
30
|
+
*/
|
|
31
|
+
readonly pages?: readonly number[];
|
|
22
32
|
readonly onDocument?: (pkg: DocumentTree) => void;
|
|
23
33
|
}
|
|
24
34
|
declare function pdfToDocx(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumentOptions): Uint8Array<ArrayBuffer>;
|
|
@@ -12,6 +12,10 @@ interface ReadNativeDocumentTreeOptions {
|
|
|
12
12
|
readonly signal?: AbortSignal;
|
|
13
13
|
readonly images?: MarkdownImageResolver;
|
|
14
14
|
readonly sink?: PdfDiagnosticSink;
|
|
15
|
+
/**
|
|
16
|
+
* The pages of a pdf source to read, exactly as UnifiedConversionOptions.pages describes them (zero-based, negative from the end, document order, `PdfPageSelectionError` for an index naming no page). Consulted only for a pdf source, since no other format's reader has pages to select. The unselected pages' content streams, the fonts and images only they use, and the source's embedded files are never read, and the selected pages are reconstructed from themselves alone (see PdfToDocumentOptions.pages for how that can change a cover page's headings). Every frame in the result names the page's index in the source PDF, so a DocumentTree read this way carries no `pages` envelope: that array is indexed by those source indices and a selection cannot fill it.
|
|
17
|
+
*/
|
|
18
|
+
readonly pages?: readonly number[];
|
|
15
19
|
}
|
|
16
20
|
type ReadContentDocumentOptions = ReadNativeDocumentTreeOptions;
|
|
17
21
|
declare function readNativeDocumentTree(format: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, options?: ReadNativeDocumentTreeOptions): DocumentTree;
|
|
@@ -19,6 +23,12 @@ declare function readContentDocument(format: DocumentFormat, bytes: Uint8Array<A
|
|
|
19
23
|
interface PdfToDocumentOptions {
|
|
20
24
|
readonly signal?: AbortSignal;
|
|
21
25
|
readonly sink?: PdfDiagnosticSink;
|
|
26
|
+
/**
|
|
27
|
+
* The pages to convert, exactly as UnifiedConversionOptions.pages describes them: zero-based page-tree indices, a negative index counted from the end, duplicates collapsed, document order, and `PdfPageSelectionError` for an index naming no page. The unselected pages' content streams, the fonts and images only they use, and the source's embedded files are never read. pdfToMarkdown labels each page it writes with its original one-based page number (`<!-- page 7 -->`), so the text says which pages it holds.
|
|
28
|
+
*
|
|
29
|
+
* Reconstruction sees only the selected pages, so a page can come out differently than it would in a full conversion. Heading detection measures text against the body size, taken as the most common size across the pages read: a cover page read on its own, dominated by large title text, takes the title's size as its body, and the title is then a paragraph rather than a heading. Reading the cover together with a few ordinary pages restores the document's real body size.
|
|
30
|
+
*/
|
|
31
|
+
readonly pages?: readonly number[];
|
|
22
32
|
readonly onDocument?: (pkg: DocumentTree) => void;
|
|
23
33
|
}
|
|
24
34
|
declare function pdfToDocx(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumentOptions): Uint8Array<ArrayBuffer>;
|
package/dist/convert/from-pdf.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import { _ as reconstructWordprocessing } from "../reconstruct-presentations-prod-
|
|
1
|
+
import { _ as reconstructWordprocessing } from "../reconstruct-presentations-prod-CC8ct-5O.js";
|
|
2
2
|
import { stampPdfPackageTables } from "./pdf-package-tables.js";
|
|
3
|
-
import { h as convertDocumentFromPdf } from "../composition-plan-
|
|
4
|
-
import { CONTENT_READERS
|
|
3
|
+
import { h as convertDocumentFromPdf } from "../composition-plan-mRolIOZY.js";
|
|
4
|
+
import { CONTENT_READERS } from "../codecs/read.js";
|
|
5
5
|
import { assembleTree } from "document-schema.js";
|
|
6
6
|
import { readPdf } from "pdf-codec/read";
|
|
7
7
|
//#region src/convert/from-pdf.ts
|
|
8
8
|
function readDocumentMetadata(format, bytes, options) {
|
|
9
|
-
if (format === "pdf") return
|
|
9
|
+
if (format === "pdf") return readPdf(bytes, {
|
|
10
|
+
signal: options?.signal,
|
|
11
|
+
pages: []
|
|
12
|
+
}).metadata;
|
|
10
13
|
return CONTENT_READERS[format](bytes, { signal: options?.signal }).metadata;
|
|
11
14
|
}
|
|
12
15
|
function readNativeContent(format, bytes, options) {
|
|
13
16
|
if (format === "pdf") {
|
|
14
17
|
const layout = readPdf(bytes, {
|
|
15
18
|
signal: options?.signal,
|
|
16
|
-
sink: options?.sink
|
|
19
|
+
sink: options?.sink,
|
|
20
|
+
pages: options?.pages
|
|
17
21
|
});
|
|
18
22
|
return {
|
|
19
23
|
content: reconstructWordprocessing(layout, { signal: options?.signal }),
|
|
@@ -28,10 +32,10 @@ function readNativeContent(format, bytes, options) {
|
|
|
28
32
|
function readNativeDocumentTree(format, bytes, options) {
|
|
29
33
|
const { content, layout } = readNativeContent(format, bytes, options);
|
|
30
34
|
if (layout !== void 0) {
|
|
31
|
-
const pages = layout.pages.map((page) => ({
|
|
35
|
+
const pages = options?.pages === void 0 ? layout.pages.map((page) => ({
|
|
32
36
|
widthPt: page.widthPt,
|
|
33
37
|
heightPt: page.heightPt
|
|
34
|
-
}));
|
|
38
|
+
})) : void 0;
|
|
35
39
|
const reported = assembleTree(content, pages);
|
|
36
40
|
stampPdfPackageTables(reported, layout);
|
|
37
41
|
return reported;
|
package/dist/convert/local.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_convert_capability = require("./capability.cjs");
|
|
3
3
|
const require_convert_port = require("./port.cjs");
|
|
4
|
-
const require_composition_plan = require("../composition-plan-
|
|
4
|
+
const require_composition_plan = require("../composition-plan-BgsXTscN.cjs");
|
|
5
5
|
const require_convert_composition_to_pdf = require("./composition-to-pdf.cjs");
|
|
6
6
|
const require_convert_convert = require("./convert.cjs");
|
|
7
7
|
//#region src/convert/local.ts
|
package/dist/convert/local.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnsupportedConversionError } from "./capability.js";
|
|
2
2
|
import { DOCUMENT_FORMATS } from "./port.js";
|
|
3
|
-
import { i as resolveCompositionPlan } from "../composition-plan-
|
|
3
|
+
import { i as resolveCompositionPlan } from "../composition-plan-mRolIOZY.js";
|
|
4
4
|
import { convertDocument } from "./composition-to-pdf.js";
|
|
5
5
|
import { odfToPdf } from "./convert.js";
|
|
6
6
|
//#region src/convert/local.ts
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let pdf_codec_layout = require("pdf-codec/layout");
|
|
2
3
|
//#region src/convert/pdf-package-tables.ts
|
|
3
4
|
function stampPdfPackageTables(pkg, layout) {
|
|
4
5
|
if (layout.destinations !== void 0 || layout.outline !== void 0) {
|
|
@@ -56,7 +57,8 @@ function stampPdfPackageTables(pkg, layout) {
|
|
|
56
57
|
...layout.source
|
|
57
58
|
};
|
|
58
59
|
const definitions = {};
|
|
59
|
-
layout.pages.forEach((page,
|
|
60
|
+
layout.pages.forEach((page, position) => {
|
|
61
|
+
const pageIndex = (0, pdf_codec_layout.sourcePageIndex)(page, position);
|
|
60
62
|
(page.annotations ?? []).forEach((annotation, annotIndex) => {
|
|
61
63
|
definitions[`pdf-annot-${String(pageIndex)}-${String(annotIndex)}`] = {
|
|
62
64
|
kind: "comment",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sourcePageIndex } from "pdf-codec/layout";
|
|
1
2
|
//#region src/convert/pdf-package-tables.ts
|
|
2
3
|
function stampPdfPackageTables(pkg, layout) {
|
|
3
4
|
if (layout.destinations !== void 0 || layout.outline !== void 0) {
|
|
@@ -55,7 +56,8 @@ function stampPdfPackageTables(pkg, layout) {
|
|
|
55
56
|
...layout.source
|
|
56
57
|
};
|
|
57
58
|
const definitions = {};
|
|
58
|
-
layout.pages.forEach((page,
|
|
59
|
+
layout.pages.forEach((page, position) => {
|
|
60
|
+
const pageIndex = sourcePageIndex(page, position);
|
|
59
61
|
(page.annotations ?? []).forEach((annotation, annotIndex) => {
|
|
60
62
|
definitions[`pdf-annot-${String(pageIndex)}-${String(annotIndex)}`] = {
|
|
61
63
|
kind: "comment",
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_xml_fragment = require("../../xml/fragment.cjs");
|
|
3
3
|
const require_xml_edit = require("../../xml/edit.cjs");
|
|
4
4
|
const require_odf_package_formula = require("../../odf-package/formula.cjs");
|
|
5
|
+
const require_xml_odf_text = require("../../xml/odf-text.cjs");
|
|
5
6
|
const require_odf_package_media = require("../../odf-package/media.cjs");
|
|
6
7
|
const require_edit_odf_repeated_runs = require("../odf-repeated-runs.cjs");
|
|
7
8
|
const require_edit_ods_address = require("./address.cjs");
|
|
@@ -63,20 +64,21 @@ function cumulativeRowOffsetPt(pkg, tableElement, anchorRow) {
|
|
|
63
64
|
if (cursor < anchorRow) offsetPt += (anchorRow - cursor) * DEFAULT_ROW_HEIGHT_PT;
|
|
64
65
|
return offsetPt;
|
|
65
66
|
}
|
|
66
|
-
function buildAbsoluteFrame(xPt, yPt, widthPt, heightPt, content) {
|
|
67
|
+
function buildAbsoluteFrame(xPt, yPt, widthPt, heightPt, content, altText) {
|
|
68
|
+
const children = altText === void 0 ? [content] : [require_xml_fragment.el("svg:title", {}, require_xml_odf_text.encodeOdfText(altText)), content];
|
|
67
69
|
return require_xml_fragment.el("draw:frame", {
|
|
68
70
|
"svg:x": (0, odf_js.formatOdfLength)(xPt),
|
|
69
71
|
"svg:y": (0, odf_js.formatOdfLength)(yPt),
|
|
70
72
|
"svg:width": (0, odf_js.formatOdfLength)(widthPt),
|
|
71
73
|
"svg:height": (0, odf_js.formatOdfLength)(heightPt)
|
|
72
|
-
},
|
|
74
|
+
}, children);
|
|
73
75
|
}
|
|
74
76
|
function insertSheetImage(pkg, tableElement, image) {
|
|
75
77
|
const { partPath } = require_odf_package_media.addImageMedia(pkg, (0, odf_js.base64ToBytes)(image.base64), image.format);
|
|
76
78
|
const xPt = cumulativeColumnOffsetPt(pkg, tableElement, image.anchorColumn) + image.offsetXPt;
|
|
77
79
|
const yPt = cumulativeRowOffsetPt(pkg, tableElement, image.anchorRow) + image.offsetYPt;
|
|
78
80
|
const imageElement = require_xml_fragment.el("draw:image", { "xlink:href": partPath });
|
|
79
|
-
const frame = buildAbsoluteFrame(xPt, yPt, image.widthPt, image.heightPt, imageElement);
|
|
81
|
+
const frame = buildAbsoluteFrame(xPt, yPt, image.widthPt, image.heightPt, imageElement, image.altText);
|
|
80
82
|
ensureTableShapes(tableElement).children.push(frame);
|
|
81
83
|
}
|
|
82
84
|
function insertSheetEmbeddedObject(pkg, tableElement, object, nextObjectName) {
|