documents.js 1.48.0 → 1.49.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=white)](https://github.com/ExaDev/documents.js) [![npm](https://img.shields.io/badge/npm-CB3837?logo=npm&logoColor=white)](https://www.npmjs.com/package/documents.js) [![Release](https://img.shields.io/github/v/release/ExaDev/documents.js)](https://github.com/ExaDev/documents.js/releases/latest) [![CI](https://img.shields.io/github/actions/workflow/status/ExaDev/documents.js/ci.yml?branch=main)](https://github.com/ExaDev/documents.js/actions)
4
4
 
5
- > Bidirectional docx/pptx/odt/odp/ods/odg ⇄ PDF conversion, a read-and-write live-view editor for docx/pptx/odt/odp/ods/odg content, and a fully hand-written PDF codec, built on [ooxml.js](https://github.com/ExaDev/ooxml.js) and [odf.js](https://github.com/ExaDev/odf.js).
5
+ > Bidirectional docx/pptx/odt/odp/ods/odg ⇄ PDF conversion, six further cross-format bridges (odt⇄docx, odp⇄pptx, ods⇄xlsx) that bypass PDF entirely, a read-and-write live-view editor for docx/pptx/odt/odp/ods/odg content, and a fully hand-written PDF codec, built on [ooxml.js](https://github.com/ExaDev/ooxml.js) and [odf.js](https://github.com/ExaDev/odf.js).
6
6
 
7
7
  `documents.js` depends on `ooxml.js` for lossless docx/pptx/xlsx ⇄ JSON handling and extends it in two directions `ooxml.js` deliberately does not cover: full PDF support (parsing arbitrary real-world PDFs and generating new ones), and a read-**and-write** manipulation API for docx/pptx content — `ooxml.js`'s own typed readers (`readDocx`/`readPptx`) are one-way and explicitly forbid write-back. PDF reading, writing, and the docx⇄PDF/pptx⇄PDF conversion pipeline are entirely hand-written: no external PDF library (`pdf-lib`, `pdfjs-dist`, `mupdf`, or any other) is a dependency. The one exception is [`fflate`](https://github.com/101arrowz/fflate) for raw DEFLATE/zlib compression underneath PDF's `FlateDecode` filter and PNG's `IDAT` chunks — the same dependency `ooxml.js` itself already relies on for ZIP handling.
8
8
 
@@ -56,6 +56,17 @@ const odsBytes2 = pdfToOds(pdfFromOds); // recovers what was printed, not what w
56
56
 
57
57
  Each accepts an optional `signal` (`AbortSignal`) and either a `onSubstitution` callback (docx/pptx/odt/odp/ods/odg → PDF, called once per character not representable in a standard-14 font) or a `sink` (PDF → docx/pptx/odt/odp/ods/odg, called once per recoverable parse diagnostic).
58
58
 
59
+ Six further conversions bypass PDF entirely: `odtToDocx`/`docxToOdt`, `odpToPptx`/`pptxToOdp`, and `odsToXlsx`/`xlsxToOds` each compose a direct `readXContent` → `buildYPackage` pivot copy, since both sides of each pair already read into and build from the identical `ContentDocument` variant — no layout engine, no font measurement, and no geometry-based reconstruction in between. See [Fidelity](#fidelity) for what that means in practice.
60
+
61
+ ```ts
62
+ import { odtToDocx, docxToOdt } from 'documents.js';
63
+
64
+ const docxBytes = odtToDocx(odtBytes);
65
+ const odtBytes2 = docxToOdt(docxBytes);
66
+ ```
67
+
68
+ Each takes an optional `{ signal }` — there is no `onSubstitution`/`sink` option here, since there is no font substitution or PDF-parse degradation to report; a wrong-kind `ContentDocument` throws outright rather than becoming a diagnostic.
69
+
59
70
  The same conversions behind a swappable port, for a caller that wants to inject a different implementation later without changing call sites:
60
71
 
61
72
  ```ts
@@ -68,6 +79,8 @@ const { document, diagnostics } = await converter.convert(
68
79
  );
69
80
  ```
70
81
 
82
+ `DocumentFormat` includes `xlsx` alongside `docx`/`pptx`/`odt`/`odp`/`ods`/`odg`/`pdf` — not because xlsx has a PDF conversion of its own, but because `createLocalDocumentConverter`'s `{ source, targetFormat }` contract already generalises past "targetFormat always means pdf": `odt`→`docx`, `docx`→`odt`, `odp`→`pptx`, `pptx`→`odp`, `ods`→`xlsx`, and `xlsx`→`ods` are six further entries in the same `conversions` list, routed to the six bridge functions above with an empty `diagnostics` array.
83
+
71
84
  Reading and editing docx/pptx content directly, without going through PDF at all:
72
85
 
73
86
  ```ts
@@ -159,7 +172,9 @@ const pdfFromDocx = z.decode(docxPdfCodec, docxBytes);
159
172
  const docxBack = z.encode(docxPdfCodec, pdfFromDocx);
160
173
  ```
161
174
 
162
- `readDocxContent`/`readPptxContent`/`readOdtContent`/`readOdpContent`/`readOdsContent`/`readOdgContent` (docx/pptx/odt/odp/ods/odg `ContentDocument`), `convertWordprocessingToLayout`/`convertPresentationToLayout`/`convertSpreadsheetToLayout`/`convertDrawingToLayout` (`ContentDocument` → `LayoutDocument`), and `reconstructWordprocessing`/`reconstructPresentation`/`reconstructSpreadsheet`/`reconstructDrawing` (`LayoutDocument` → `ContentDocument`) are each exported individually too, for a caller that wants one stage of the pipeline without the rest. `readDocxContent` and `readOdtContent` both produce the identical `wordprocessing`-variant `ContentDocument` shape from two completely unrelated package formats (OOXML and ODF), which is what lets `odtToPdf` feed `convertWordprocessingToLayout` without a single line of that engine changing; `readPptxContent` and `readOdpContent` do the same for the `presentation` variant and `convertPresentationToLayout`. `readOdsContent`/`convertSpreadsheetToLayout` and `readOdgContent`/`convertDrawingToLayout` each have no OOXML-side counterpart at all (no `readXlsxContent`/xlsx layout, no drawing-equivalent OOXML format this package reads) — both `convertSpreadsheetToLayout` and `convertDrawingToLayout` are genuinely new layout algorithms, since a spreadsheet's addressed-grid-with-print-settings semantics and a drawing's vector-primitive vocabulary (rect/ellipse/line/path) have no flow/pagination or direct-placement analogue; `convertDrawingToLayout` does still reuse `convertPresentationToLayout`'s own shape-conversion logic (`convertShape`, exported from `src/layout/slides.ts`) verbatim for whatever text/image/table content a drawing page also carries. `reconstructDrawing` is `reconstructWordprocessing`/`reconstructPresentation`'s drawing-side counterpart, but does no baseline/paragraph clustering at all — a drawing has no semantic structure to recover, only a near-1:1 `LayoutItem` → `ContentVector`/`ContentShape` mapping to make, in the same paint order the items were recovered in. `reconstructSpreadsheet` is a genuinely different geometry-recovery problem from either: a real gridline lattice on the page (drawn by a printed sheet with gridlines enabled) is used DIRECTLY as cell boundaries when one is detected; absent one, text is clustered into a 2D grid from geometry alone. It recovers what was printed, not what was entered — every cell comes back a bare string, never re-parsed into a number/date/boolean or claimed as a formula (see [Fidelity](#fidelity)).
175
+ The six PDF-bypassing bridges above get the same treatment: `odtDocxCodec`, `odpPptxCodec`, and `odsXlsxCodec` (odt bytes docx bytes, odp bytes pptx bytes, ods bytes xlsx bytes) — the no-options form again, `odtToDocx`/`docxToOdt`/etc. remain the entry points for `signal`.
176
+
177
+ `readDocxContent`/`readPptxContent`/`readOdtContent`/`readOdpContent`/`readOdsContent`/`readOdgContent` (docx/pptx/odt/odp/ods/odg → `ContentDocument`), `convertWordprocessingToLayout`/`convertPresentationToLayout`/`convertSpreadsheetToLayout`/`convertDrawingToLayout` (`ContentDocument` → `LayoutDocument`), and `reconstructWordprocessing`/`reconstructPresentation`/`reconstructSpreadsheet`/`reconstructDrawing` (`LayoutDocument` → `ContentDocument`) are each exported individually too, for a caller that wants one stage of the pipeline without the rest. `readDocxContent` and `readOdtContent` both produce the identical `wordprocessing`-variant `ContentDocument` shape from two completely unrelated package formats (OOXML and ODF), which is what lets `odtToPdf` feed `convertWordprocessingToLayout` without a single line of that engine changing; `readPptxContent` and `readOdpContent` do the same for the `presentation` variant and `convertPresentationToLayout`. `readOdgContent`/`convertDrawingToLayout` has no OOXML-side counterpart at all (no drawing-equivalent OOXML format this package reads); `readOdsContent`/`convertSpreadsheetToLayout` now does have one on the read side — `ooxml.js`'s own `readXlsxContent` — but only for the PDF-bypassing `odsToXlsx`/`xlsxToOds` bridge below, not for the PDF pivot: xlsx has no PDF conversion of its own, so `convertSpreadsheetToLayout` still has no xlsx-layout counterpart to reuse or be reused by. Both `convertSpreadsheetToLayout` and `convertDrawingToLayout` are genuinely new layout algorithms, since a spreadsheet's addressed-grid-with-print-settings semantics and a drawing's vector-primitive vocabulary (rect/ellipse/line/path) have no flow/pagination or direct-placement analogue; `convertDrawingToLayout` does still reuse `convertPresentationToLayout`'s own shape-conversion logic (`convertShape`, exported from `src/layout/slides.ts`) verbatim for whatever text/image/table content a drawing page also carries. `reconstructDrawing` is `reconstructWordprocessing`/`reconstructPresentation`'s drawing-side counterpart, but does no baseline/paragraph clustering at all — a drawing has no semantic structure to recover, only a near-1:1 `LayoutItem` → `ContentVector`/`ContentShape` mapping to make, in the same paint order the items were recovered in. `reconstructSpreadsheet` is a genuinely different geometry-recovery problem from either: a real gridline lattice on the page (drawn by a printed sheet with gridlines enabled) is used DIRECTLY as cell boundaries when one is detected; absent one, text is clustered into a 2D grid from geometry alone. It recovers what was printed, not what was entered — every cell comes back a bare string, never re-parsed into a number/date/boolean or claimed as a formula (see [Fidelity](#fidelity)).
163
178
 
164
179
  ## Architecture
165
180
 
@@ -174,9 +189,9 @@ The package is layered from generic primitives outward to the two conversion dir
174
189
  - **Read**: `lexer.ts`/`parse.ts` (byte tokenizer and tokens → `PdfObject`), `filters.ts`/`predictors.ts` (Flate/LZW/ASCII85/ASCIIHex/RunLength, TIFF/PNG predictors), `xref.ts`/`document.ts` (classic and cross-reference-stream resolution, object streams, `/Prev` chains, linear-scan recovery, the page tree with attribute inheritance), `content-read.ts`/`interpret.ts` (the content-stream tokenizer and graphics/text state machine, including form-XObject recursion), `cmap.ts`/`font-style.ts`/`font-read.ts` (`/ToUnicode` CMaps, font-dictionary resolution), `images-read.ts` (Image XObjects → PNG/JPEG bytes), `read.ts` (`readPdf`, assembling all of the above into a `LayoutDocument`).
175
190
  - `codec.ts` — `pdfCodec`, a `z.codec()` pair over `readPdf`/`writePdf` (PDF bytes ⇄ `LayoutDocument`).
176
191
  - **`src/ooxml/`** — resolves a `Package` into a `ContentDocument`: `docx/read.ts` and `pptx/read.ts` are now thin adapters over `ooxml.js`'s own `readDocx`/`readPptx`, wrapping their `{ metadata, sections }`/`{ metadata, slides }` result into `ContentDocument`'s `wordprocessing`/`presentation` shape. The docx style cascade (`docDefaults` → named-style `basedOn` chains → paragraph-mark run properties → character styles → direct formatting), the pptx placeholder → layout → master → theme inheritance cascade, and DrawingML geometry/colour resolution all now live upstream in `ooxml.js` itself, not in this package.
177
- - **`src/odf/`** — the ODF-side counterpart to `src/ooxml/`, resolving an `odf.js` `Package` into a `ContentDocument`: `odt/read.ts`'s `readOdtContent` is a thin adapter over `odf.js`'s own `readOdt`, wrapping its `{ metadata, sections }` result into the identical `wordprocessing` shape `readDocxContent` produces — the concrete proof that odt and docx genuinely share one pivot and one layout engine. `odp/read.ts`'s `readOdpContent` is the same adapter over `odf.js`'s `readOdp`, wrapping `{ metadata, slides }` into the identical `presentation` shape `readPptxContent` produces. `ods/read.ts`'s `readOdsContent` wraps `odf.js`'s `readOds`'s `{ metadata, sheets }` into the `spreadsheet` `ContentDocument` variant, and `odg/read.ts`'s `readOdgContent` wraps `odf.js`'s `readOdg`'s `{ metadata, pages }` into the `drawing` variant — neither has an OOXML-side sibling adapter (there is no `readXlsxContent`, and no drawing-equivalent OOXML format this package reads at all). `buildOdtPackage`/`buildOdpPackage`/`buildOdsPackage`/`buildOdgPackage` (`src/edit/{odt,odp,ods,odg}/content.ts`) each bridge a `ContentDocument` back to a fresh package built on that format's own live-view editor, closing the PDF → odt/odp/ods/odg direction (`pdfToOdt`/`pdfToOdp`/`pdfToOds`/`pdfToOdg` each call the matching one) — see the `pdfToOds` gotcha below for `buildOdsPackage`'s own printSettings-writing addition.
192
+ - **`src/odf/`** — the ODF-side counterpart to `src/ooxml/`, resolving an `odf.js` `Package` into a `ContentDocument`: `odt/read.ts`'s `readOdtContent` is a thin adapter over `odf.js`'s own `readOdt`, wrapping its `{ metadata, sections }` result into the identical `wordprocessing` shape `readDocxContent` produces — the concrete proof that odt and docx genuinely share one pivot and one layout engine. `odp/read.ts`'s `readOdpContent` is the same adapter over `odf.js`'s `readOdp`, wrapping `{ metadata, slides }` into the identical `presentation` shape `readPptxContent` produces. `ods/read.ts`'s `readOdsContent` wraps `odf.js`'s `readOds`'s `{ metadata, sheets }` into the `spreadsheet` `ContentDocument` variant, and `odg/read.ts`'s `readOdgContent` wraps `odf.js`'s `readOdg`'s `{ metadata, pages }` into the `drawing` variant — `odg` still has no OOXML-side sibling adapter at all (no drawing-equivalent OOXML format this package reads); `ods` now does, `ooxml.js`'s own `readXlsxContent`/`buildXlsxPackage`, consumed directly by `src/convert/convert.ts`'s `odsToXlsx`/`xlsxToOds` bridge (see below) but deliberately not re-exported from this package's own public surface, mirroring the `readDocx`/`readPptx` non-re-export choice above. `buildOdtPackage`/`buildOdpPackage`/`buildOdsPackage`/`buildOdgPackage` (`src/edit/{odt,odp,ods,odg}/content.ts`) each bridge a `ContentDocument` back to a fresh package built on that format's own live-view editor, closing the PDF → odt/odp/ods/odg direction (`pdfToOdt`/`pdfToOdp`/`pdfToOds`/`pdfToOdg` each call the matching one) — see the `pdfToOds` gotcha below for `buildOdsPackage`'s own printSettings-writing addition.
178
193
  - **`src/layout/`** — the pure conversion algorithms, importing only `model` (no I/O): `engine.ts` (`ContentDocument` wordprocessing → `LayoutDocument`: flow, line-breaking, pagination — fed identically by docx- and odt-sourced content), `slides.ts` (`ContentDocument` presentation → `LayoutDocument`: direct EMU-to-point placement, no pagination needed — fed identically by pptx- and odp-sourced content; also exports `convertShape`, the single-`ContentShape`-to-`LayoutItem[]` conversion `drawing.ts` below reuses verbatim), `sheets.ts` (`ContentDocument` spreadsheet → `LayoutDocument`: resolve the print range, build cumulative column/row offsets skipping hidden ones, reserve header/repeat-row-column space, resolve an explicit or non-iterative fit-to-page scale, partition into column/row bands honouring manual breaks with the same "an oversized item gets its own band and overflows rather than looping" guarantee `engine.ts`'s `ensureRoom` documents, emit pages in `downThenOver`/`overThenDown` order, then per page paint backgrounds/gridlines/headers/cell text with default alignment by value kind and `###`/spill-then-truncate overflow handling — the first layout algorithm in this package that accepts an `AbortSignal`, since a 50k-cell sheet needs cancellation where a docx/pptx page count never did), `drawing.ts` (`ContentDocument` drawing → `LayoutDocument`: one `ContentDrawPage` per PDF page, direct placement like `slides.ts`, with one new emission path — a `ContentVector` `rect`/`ellipse`/`line` maps onto the pre-existing `LayoutRect`/`LayoutEllipse`/`LayoutLine` kinds, and a `path` vector's local, viewBox-relative subpath points are resolved through the vector's own frame offset then a single page-space flip into a `LayoutPath` value; vectors paint before shapes, a documented, bounded choice — see this module's own top-of-file note — since `ContentDrawPageSchema` keeps `shapes` and `vectors` as two independently paint-ordered arrays with no field recording their relative order when the two genuinely overlap), `reconstruct.ts` (`LayoutDocument` → `ContentDocument`: `reconstructWordprocessing`/`reconstructPresentation` do baseline-proximity line clustering, then paragraph/text-block clustering from geometry — PDF has no semantic paragraph or shape structure to recover, only positioned glyphs; `reconstructDrawing` does no clustering at all, since a drawing has no such structure to infer in the first place — every `LayoutItem` maps close to 1:1 back onto a `ContentVector` `rect`/`ellipse`/`line`/`path` or a `ContentShape`, in the exact z-order it was painted, bucketed into `ContentDrawPageSchema`'s own two independently-ordered `shapes`/`vectors` arrays the same way `drawing.ts` produced them; `reconstructSpreadsheet` tries a real gridline lattice first — scanning the page's `LayoutLine`/stroked-single-segment-`LayoutPath` items for enough parallel horizontal and vertical lines at consistent positions to call it a printed grid, using those line positions directly as cell boundaries when found — and falls back to text-position clustering otherwise, reusing this same module's `clusterIntoLines` for rows and a parallel recurring-x-position generalisation of `clusterIntoParagraphs`'s own `dominantLeftX` for columns; every recovered cell is a bare string, column widths/row heights are genuinely measured from whichever geometry was used, and no print range/scale/repeat-rows/repeat-columns/manual-breaks are ever inferred).
179
- - **`src/convert/`** — `convert.ts` (the twelve round-trip ergonomic wrappers), `codec.ts` (`docxPdfCodec`/`pptxPdfCodec`/`odtPdfCodec`/`odpPdfCodec`/`odsPdfCodec`/`odgPdfCodec`, a `z.codec()` pair over each), `port.ts`/`local.ts` (the swappable `DocumentConverter` contract and its synchronous local implementation, covering `docx`/`pptx`/`odt`/`odp`/`ods`/`odg` → `pdf` and `pdf` → `docx`/`pptx`/`odt`/`odp`/`ods`/`odg`).
194
+ - **`src/convert/`** — `convert.ts` (the twelve PDF-pivot round-trip ergonomic wrappers, plus a dedicated "Six cross-format bridges" section: `odtToDocx`/`docxToOdt`, `odpToPptx`/`pptxToOdp`, `odsToXlsx`/`xlsxToOds`, each a direct `readXContent` → `buildYPackage` composition bypassing PDF entirely — see [Fidelity](#fidelity)), `codec.ts` (`docxPdfCodec`/`pptxPdfCodec`/`odtPdfCodec`/`odpPdfCodec`/`odsPdfCodec`/`odgPdfCodec` plus `odtDocxCodec`/`odpPptxCodec`/`odsXlsxCodec`, a `z.codec()` pair over each), `port.ts`/`local.ts` (the swappable `DocumentConverter` contract and its synchronous local implementation, covering `docx`/`pptx`/`odt`/`odp`/`ods`/`odg` → `pdf`, `pdf` → `docx`/`pptx`/`odt`/`odp`/`ods`/`odg`, and the six bridge pairs — `DocumentFormat` includes `xlsx` for exactly this reason, even though xlsx has no PDF conversion of its own).
180
195
 
181
196
  Dependency direction is strictly downward and checkable: `model`/`bytes` import nothing local; `image` imports `bytes` only; `pdf` imports `model`+`bytes`+`image` only; `ooxml/*` imports `xml`/`model` only (no PDF knowledge); `odf/*` imports `model` only (no PDF knowledge, no `xml/*` — `odf.js` already owns its own XML query helpers); `layout` imports `model` only; `convert` composes everything else. No `PdfObject`/`PdfDict`/`PdfStream` type appears outside `src/pdf/`.
182
197
 
@@ -197,7 +212,7 @@ To run a single test file: `pnpm vitest run src/path/to/file.test.ts`.
197
212
  ## Conventions
198
213
 
199
214
  - **Zod-first schema/type/guard**, matching `ooxml.js`: every model type is inferred from its Zod schema, never hand-written. `ContentBlock` (recursive, mirroring `ooxml.js`'s own `XmlNode` treatment) uses a hand-written structural guard + `z.custom`, not `z.lazy`, which collapses to `unknown` for recursive element-children in the pinned Zod version.
200
- - **`z.codec()` for every schema-to-schema round trip**, matching `ooxml.js`'s `packageCodec`/`xmlCodec`: `pdfCodec` (PDF bytes ⇄ `LayoutDocument`) and `docxPdfCodec`/`pptxPdfCodec`/`odtPdfCodec`/`odpPdfCodec`/`odsPdfCodec`/`odgPdfCodec` (docx/pptx/odt/odp/ods/odg bytes ⇄ PDF bytes) each wrap an already-independently-tested function pair, adding automatic two-way schema validation. These are deliberately the no-options form — `readPdf`/`writePdf`/`docxToPdf`/`pdfToDocx`/`pptxToPdf`/`pdfToPptx`/`odtToPdf`/`pdfToOdt`/`odpToPdf`/`pdfToOdp`/`odsToPdf`/`pdfToOds`/`odgToPdf`/`pdfToOdg` remain the primary entry points wherever a caller needs an `AbortSignal`, a `PdfDiagnosticSink`, or an `onSubstitution` callback, since `z.codec()`'s fixed `decode(input)`/`encode(output)` signature has no room for side-channel options.
215
+ - **`z.codec()` for every schema-to-schema round trip**, matching `ooxml.js`'s `packageCodec`/`xmlCodec`: `pdfCodec` (PDF bytes ⇄ `LayoutDocument`), `docxPdfCodec`/`pptxPdfCodec`/`odtPdfCodec`/`odpPdfCodec`/`odsPdfCodec`/`odgPdfCodec` (docx/pptx/odt/odp/ods/odg bytes ⇄ PDF bytes), and `odtDocxCodec`/`odpPptxCodec`/`odsXlsxCodec` (odt/odp/ods bytes ⇄ docx/pptx/xlsx bytes, the PDF-bypassing bridges) each wrap an already-independently-tested function pair, adding automatic two-way schema validation. These are deliberately the no-options form — `readPdf`/`writePdf`/`docxToPdf`/`pdfToDocx`/`pptxToPdf`/`pdfToPptx`/`odtToPdf`/`pdfToOdt`/`odpToPdf`/`pdfToOdp`/`odsToPdf`/`pdfToOds`/`odgToPdf`/`pdfToOdg`/`odtToDocx`/`docxToOdt`/`odpToPptx`/`pptxToOdp`/`odsToXlsx`/`xlsxToOds` remain the primary entry points wherever a caller needs an `AbortSignal`, a `PdfDiagnosticSink`, or an `onSubstitution` callback, since `z.codec()`'s fixed `decode(input)`/`encode(output)` signature has no room for side-channel options.
201
216
  - **`PdfObject` has no Zod schema at all**, deliberately: it never crosses a public boundary or round-trips through JSON, and is constructed exclusively by this package's own parser — validating it would just be validating our own output. It narrows natively on its own `kind` discriminant instead, the same reasoning `ooxml.js` applies when it picks a hand-written `isXmlNode` guard over `z.lazy`.
202
217
  - **No type assertions anywhere.** Every third-party or loosely-typed value is narrowed through a type guard or a Zod parse at the boundary.
203
218
  - **Live views, not flatten-and-regenerate.** `src/edit/*`'s editor classes hold a reference directly into the real `Package`/`XmlElement` objects; saving is `encodePackage(pkg)`, nothing more. This is what makes "everything you didn't touch stays byte-faithful" a structural guarantee rather than a best effort.
@@ -207,7 +222,10 @@ To run a single test file: `pnpm vitest run src/path/to/file.test.ts`.
207
222
  ## Gotchas and quirks
208
223
 
209
224
  - **`ooxml.js`'s typed readers (`readDocx`/`readPptx`) are now the actual basis for conversion** — `readDocxContent`/`readPptxContent` are thin wrappers around them, not an independent walk of `word/document.xml`/`ppt/slides/slideN.xml`. They are still deliberately not re-exported from this package's own public surface: `readDocx`/`readPptx` also carry `comments`/`footnotes`/`headers`/`footers` (docx) that `ContentDocument` doesn't model, so exposing both the wrapper and the thing it wraps would invite a caller to reach for the wrong one rather than genuinely offering two competing models.
210
- - **The docx⇄PDF and pptx⇄PDF conversions are explicitly not round-trip-lossless** — in deliberate contrast to `ooxml.js`'s own `packageCodec`, which is byte/part-faithful by design. See [Fidelity](#fidelity).
225
+ - **The docx⇄PDF and pptx⇄PDF conversions are explicitly not round-trip-lossless** — in deliberate contrast to `ooxml.js`'s own `packageCodec`, which is byte/part-faithful by design. See [Fidelity](#fidelity). The six cross-format bridges below (`odtToDocx`/`docxToOdt`, `odpToPptx`/`pptxToOdp`, `odsToXlsx`/`xlsxToOds`) are a genuinely different case — see the [Fidelity](#fidelity) section's own paragraph on them.
226
+ - **Building the six cross-format bridges surfaced two real, previously-undiscovered gaps in existing `populateParagraph` write paths, both now fixed.** `buildDocxPackage`'s `populateParagraph` (`src/edit/docx/content.ts`) never wrote a paragraph's own `list` membership back (`ContentParagraph.list`, docx's flat `numId`/`level` model) — only read, never written, since no existing caller had ever round-tripped a list-bearing paragraph through it. `buildOdtPackage`'s `populateParagraph` (`src/edit/odt/content.ts`) never wrote a paragraph's own `styleId` back at all (`readOdtContent`/`readOdfParagraph` in `odf.js` reads it unconditionally from `text:style-name`, but nothing on the write side ever set that attribute). Both are now fixed: `DocxParagraph.list` is set unconditionally alongside `styleId`/`alignment`, matching that function's own existing pattern; `OdtParagraph.styleId` is set conditionally alongside `alignment`, matching odt's own local convention. `buildOdtPackage` additionally gained `appendBlocks`/`appendListRun` (`src/edit/odt/content.ts`) — ODF has no flat per-paragraph list property to set the way docx does, so a run of consecutive `ContentParagraph`s sharing `list.numId` is grouped and written as a real, potentially multi-level `text:list`/`text:list-item` tree via `OdtList`/`OdtListItem`, the structural inverse of `odf.js`'s own list-reading (a fresh `text:list` per `numId` change, one level of nesting per `list.level` step, descending only one level at a time since ODF can only open a nested list from inside an existing item). Both gaps were invisible before this task specifically because nothing had previously round-tripped a list-bearing paragraph or a styled paragraph through `docx ⇄ odt` at all — the PDF-pivot conversions never exercised `buildDocxPackage`/`buildOdtPackage` on content read back from the OTHER format.
227
+ - **A table shape inside an odp slide does not survive `odpToPptx`.** `buildPptxPackage`'s `appendShape` (`src/edit/pptx/content.ts`) silently drops any non-paragraph block found inside a shape's own text-box loop — a scope choice whose own comment ("PDF-reconstructed shapes never mix kinds") assumed its only caller was the PDF-reconstruction path, where that is true. `odpToPptx` is a second, non-PDF-reconstructed caller for which it is not: a real odp `draw:frame` containing a `table:table` directly (not inside a text box) reads as a `ContentShape` with a `'table'` block, and that block is silently dropped, leaving an empty pptx text box where the table was. Everything else on the same slide — a rotated shape, grouped shapes, an image, speaker notes — survives correctly (see `src/convert/bridges.test.ts`'s own dedicated fidelity-gap test, which proves both halves against the existing `minimalOdpBytes()` fixture). A real, tracked, bounded gap, not a silent one: closing it means teaching `buildPptxPackage`/`buildOdpPackage` to write a real table into a slide shape, a materially larger feature than this bridge's own scope.
228
+ - **The `ods ⇄ xlsx` bridge inherits several real, format-boundary fidelity limits from `ooxml.js`'s brand-new `readXlsxContent`/`buildXlsxPackage`, on top of its own pivot-copy design.** xlsx has no `percentage`/`currency` cell type of its own (both are a plain numeric cell plus a number-format style neither this reader nor this writer interprets) — an ods `percentage`/`currency` cell survives the `odsToXlsx` hop with its numeric *value* intact but downgrades to a plain `number` *kind*, permanently (currency's own currency code is dropped outright). xlsx also has only one rare `t="d"` cell type covering BOTH date and time — an ods `time` cell survives as a `date`-kind cell carrying its original value string verbatim, but mislabelled; an ods `date` cell is unaffected (it was already the kind xlsx's own `t="d"` maps onto). A formula (`table:formula`/`<f>`) is carried completely verbatim in both directions — never parsed, translated, or evaluated by either this package's own reader or writer — but a REAL spreadsheet application does evaluate a workbook's own `<f>`/`table:formula` on open: confirmed against genuine LibreOffice 26.2, an ods formula authored in OpenFormula syntax (`of:=[.B2]*2`) becomes a formula ERROR (`Err:510`) when the bridged xlsx is opened in real Calc, even though the formula's own cached value is still present and correctly readable via `readXlsxContent` — going the other way is less fragile in practice only because a genuine xlsx formula (bare Excel A1 syntax, e.g. `B2*2`) happens to still parse under LibreOffice's own more lenient, backward-compatible ODF formula grammar, not because of anything this bridge does differently in either direction. Column widths survive the `odsToXlsx` hop within roughly a pixel of rounding tolerance (see `src/convert/bridges.test.ts`'s own `COLUMN_WIDTH_TOLERANCE_PT`) but are then dropped entirely on the return `xlsxToOds` hop — not a character-width-unit rounding loss, but `buildOdsPackage` not writing `ContentSheetColumn.widthPt` at all, a pre-existing, already-documented gap in that file's own module comment, unrelated to and unfixed by this bridge. A boolean cell written by `buildXlsxPackage` renders as a raw `1`/`0` rather than `TRUE`/`FALSE` when opened in real Excel/Calc, since that writer's own genuinely-minimal `xl/styles.xml` (one default cell format, no boolean-specific number format) has nothing else to apply — the underlying `{ kind: 'boolean', value: true }` is still read back correctly by `readXlsxContent` regardless; this is a real-application *display* gap, not a data-fidelity one. `readXlsxContent`'s own cell.value.kind never produces `'error'` from an odf.js-sourced document at all, for a structural reason rather than a bug: ODF's `office:value-type` enumeration has no `error` member, so `OdsCell.value`'s own write-side choice for a `kind: 'error'` cell is to write it as a genuine, non-empty `office:string-value` carrying the error's own text — an `xlsxToOds` → `odsToXlsx` round trip of a genuine xlsx `t="e"` error cell therefore turns it into a plain `string` cell carrying the identical text; the message survives, the `error` semantic does not.
211
229
  - **`odpToPdf`/`pdfToOdp` needed zero new layout code.** `readOdpContent` (`src/odf/odp/read.ts`) produces the identical `presentation` `ContentDocument` shape `readPptxContent` does, so it feeds `convertPresentationToLayout` unmodified — including the existing hidden-annotation speaker-notes mechanism below, which carries odp's `presentation:notes` through to the PDF with no new notes-handling code at all; `pdfToOdp` reuses `reconstructPresentation` unmodified too, the same architectural bet `pdfToOdt` already proved for `reconstructWordprocessing`. The genuinely new work for the reverse direction was the live-view editor itself (`src/edit/odp/*`) — see Architecture above.
212
230
  - **`OdpShape.rotationDeg` writes a real `draw:transform`, built on `odf.js`'s own transform machinery.** It is the write-side inverse of `odf.js`'s `resolveOdfShapeGeometry` (`typed/shared/transform.ts`), built on that module's own exported `applyOdfTransform` rather than a hand-rolled rotation matrix, so it inherits that module's own empirically-verified rotate/translate composition order and sign convention by construction. Unlike `PptxShape` (see the `colSpan`/`rowSpan` gotcha below, which pptx still has and odp does not), `buildOdpPackage` writes a rotated shape's rotation back correctly — verified both by this package's own tests and by opening a fresh, editor-built `.odp` in actual LibreOffice.
213
231
  - **`src/pdf/interpret.ts` tracks general vector paths, not just axis-aligned `re` rectangles.** `m`/`l`/`c`/`v`/`y`/`h` (and `re` itself, per its own ISO 32000-1 definition as a 4-point rectangle subpath) accumulate real subpaths — CTM-transformed line/cubic segments, open or closed — and any paint operator (`f`/`F`/`f*`/`S`/`s`/`B`/`B*`/`b`/`b*`) emits a `LayoutPath` item when the path isn't reducible to the simple single-`re`-on-an-axis-aligned-CTM case (which still takes the original, unchanged `LayoutRect` fast path). Verified both by dedicated tests and by a genuine `writePath` → `writePdf` → `readPdf` round trip recovering the original `LayoutPath` value exactly. This is the shared infrastructure both `pdfToOds` and `reconstructDrawing` need; both now use it. A direct, practical consequence for `pdfToOds`: `readPdf` never reconstructs a `'line'` kind item at all (see the `reconstructDrawing` gotcha below), so a gridline written by `sheets.ts`'s own `renderGridlines` always comes back from a real PDF round trip as a generic, single-subpath, single-line-segment, stroke-only `LayoutPath` — `reconstructSpreadsheet`'s own gridline-lattice detection accepts both shapes (a genuine `LayoutLine` item and this stroked-single-segment `LayoutPath` shape) for exactly this reason.
@@ -246,6 +264,8 @@ To run a single test file: `pnpm vitest run src/path/to/file.test.ts`.
246
264
 
247
265
  Neither direction is round-trip-lossless, and no conversion is the exact inverse of its own reverse direction — `pdfToDocx(docxToPdf(x))` will not reproduce `x` exactly, and neither will `pdfToOdg(odgToPdf(x))` or `pdfToOds(odsToPdf(x))`; neither is intended to. This is a deliberate, permanent contrast with `ooxml.js`'s own `packageCodec`, which genuinely is a lossless round trip. `docxPdfCodec`/`pptxPdfCodec`/`odtPdfCodec`/`odpPdfCodec`/`odsPdfCodec`/`odgPdfCodec`/`pdfCodec` share `packageCodec`'s *mechanism* (`z.codec()`, schema-validated both ways) but not its *guarantee* — wrapping a lossy conversion in `z.codec()` validates the shape of what comes out, not its fidelity to what went in.
248
266
 
267
+ **The six cross-format bridges (`odtToDocx`/`docxToOdt`, `odpToPptx`/`pptxToOdp`, `odsToXlsx`/`xlsxToOds`) are a categorically different case from every conversion above: they bypass the PDF pivot entirely, so the "not round-trip-lossless" caveat that applies to every PDF-pivot conversion in this section does not carry over to them.** There is no layout engine (no flow, no line-wrapping, no pagination) and no geometry-based reconstruction (no baseline clustering, no gridline-lattice detection) anywhere in a bridge's own call path — each is nothing more than `buildYPackage(readXContent(decodePackage(bytes)))`, composing the identical reader/builder pair the PDF-pivot conversions on either side of the bridge already use, because both formats in each pair read into and build from the exact same `ContentDocument` variant. Concretely, for `odt ⇄ docx` and `odp ⇄ pptx`: text, run styling (bold/italic/underline/colour/font/size), paragraph `styleId`, list membership and nesting level, table structure and cell content, and (for `odp ⇄ pptx`) speaker notes all survive completely — proven by `src/convert/bridges.test.ts`'s own dedicated round-trip suite, exercised in both directions from both starting formats, and cross-checked by opening genuinely LibreOffice-produced source files and their bridged output in real LibreOffice (see that test file and this repo's own verification notes). The one confirmed gap is a table shape nested inside an odp/pptx slide shape, not the document/presentation structure itself — see the gotcha above. `ods ⇄ xlsx` preserves cell values, formulas (verbatim), and merged ranges completely, and column widths within a roughly one-pixel rounding tolerance on the `odsToXlsx` hop — but, being built on `ooxml.js`'s brand-new `readXlsxContent`/`buildXlsxPackage`, carries several real, honestly-documented format-boundary limits of its own (percentage/currency downgrading to a plain number, time collapsing into date, xlsx column widths not surviving the `xlsxToOds` return hop, and a formula written in one dialect showing as a genuine formula error in a REAL spreadsheet application expecting the other) — see the `ods ⇄ xlsx` gotcha above for the full, specific list. None of this is layout drift or reconstruction guesswork; every gap listed is a genuine format-boundary limit (a cell type, a value kind, or a write-side omission that exists independently of this bridge), not an approximation introduced by the bridge itself.
268
+
249
269
  **Optional real-world corpus.** `test/corpus/` (gitignored, never committed) holds a `pnpm test:corpus` vitest project for manual conformance checking against real PDFs a hand-built fixture can't fully stand in for — a Word "Save as PDF", a PowerPoint "Save as PDF", a Chrome "Print to PDF", a LibreOffice export. It is not part of `pnpm test` and does not gate CI; drop files in locally before a significant parser change.
250
270
 
251
271
  ## Release and publishing
@@ -260,7 +280,7 @@ Commits follow Conventional Commits (`feat:`, `fix:`, `test:`, `chore:`, …), e
260
280
 
261
281
  ## References
262
282
 
263
- - [ooxml.js](https://github.com/ExaDev/ooxml.js) — the sibling package this depends on for all docx/pptx/xlsx ⇄ JSON handling and cascade-resolved typed reading.
283
+ - [ooxml.js](https://github.com/ExaDev/ooxml.js) — the sibling package this depends on for all docx/pptx/xlsx ⇄ JSON handling and cascade-resolved typed reading, including its own `readXlsxContent`/`buildXlsxPackage` (a `ContentDocument`-shaped xlsx reader/writer pair), consumed directly by `src/convert/convert.ts`'s `odsToXlsx`/`xlsxToOds` bridge but not re-exported from this package's own public surface.
264
284
  - [document-content-model](https://github.com/ExaDev/document-content-model) — the sibling package that owns `ContentDocument`/`LayoutDocument` themselves; both `ooxml.js` and `documents.js` import from it rather than each maintaining an independent copy.
265
285
  - [odf.js](https://github.com/ExaDev/odf.js) — a sibling package doing the equivalent lossless-codec job for the OpenDocument Format (odt/ods/odp/odg/…), also built on `document-content-model`. A dependency of `documents.js` for: this package's `Odt`/`Ods`/`Odp`/`OdgBytesSchema` (`src/model/bytes.ts`), which validate against its `ODF_MEDIA_TYPES` table; `src/interop.test.ts`, a type-level guard that `ooxml.js`'s and `odf.js`'s raw `XmlElement`/`XmlNode`/`Attribute`/`Package` container types stay structurally compatible; `src/odf/odt/read.ts`'s `readOdtContent`, a thin adapter over `odf.js`'s own `readOdt`, feeding `odtToPdf`/`pdfToOdt` (`src/convert/convert.ts`); `src/odf/odp/read.ts`'s `readOdpContent`, the same adapter over `odf.js`'s `readOdp`, feeding `odpToPdf`/`pdfToOdp`; `src/odf/ods/read.ts`'s `readOdsContent`, the same adapter over `odf.js`'s `readOds`, feeding `odsToPdf`/`pdfToOds`, and reused directly by `src/edit/ods/print-settings.ts`'s own `readSheetPrintSettings` (`findStyleElement`/`resolvePageLayoutProperties`/`parsePageSize`/`parseMargins`, the same style-chain-resolution primitives `readOds`'s own `readPrintSettings` is built on); `src/odf/odg/read.ts`'s `readOdgContent`, the same adapter over `odf.js`'s `readOdg` — including its own `typed/shared/path.ts`, the real-LibreOffice-output-verified `svg:d`/`draw:points` parser this package's `writePath` content is ultimately sourced from, and which `src/edit/odg/svg-path.ts`'s `buildSvgPathData` (the write-side inverse) also cross-checks its own output against directly — feeding `odgToPdf`/`pdfToOdg` (the latter re-reading a rebuilt package's own real geometry through this same `readOdg`, not just writing one); `src/edit/odt/*`'s `StyleRegistry`/`resolveStyle` (style interning), `src/edit/odp/shape.ts`'s `applyOdfTransform`/`resolveOdfShapeGeometry` (rotation), and `src/edit/odt/automatic-styles.ts`'s `ensureAutomaticStyles`/`nextStyleName` (reused by `src/edit/odg/style.ts`'s own graphic-family style writer and `src/edit/ods/print-settings.ts`'s own page-layout/master-page/table-style minting), all consumed directly rather than reimplemented. odt, odp, ods, and odg → `ContentDocument` reading and PDF conversion are now all integrated both ways.
266
286
 
package/dist/index.cjs CHANGED
@@ -80,6 +80,7 @@ function zipBytesSchema(label) {
80
80
  }
81
81
  const DocxBytesSchema = zipBytesSchema("docx");
82
82
  const PptxBytesSchema = zipBytesSchema("pptx");
83
+ const XlsxBytesSchema = zipBytesSchema("xlsx");
83
84
  const PdfBytesSchema = zod.z.instanceof(Uint8Array).refine((bytes) => containsBytesWithin(bytes, PDF_HEADER, PDF_HEADER_SEARCH_WINDOW), { message: "not a valid PDF file: missing the %PDF- header" });
84
85
  const MIMETYPE_ENTRY_FILENAME = "mimetype";
85
86
  const MIMETYPE_FILENAME_OFFSET = 30;
@@ -1095,6 +1096,7 @@ function buildDocxPackage(content) {
1095
1096
  function populateParagraph$1(paragraph, block) {
1096
1097
  paragraph.styleId = block.styleId;
1097
1098
  paragraph.alignment = block.alignment;
1099
+ paragraph.list = block.list;
1098
1100
  for (const run of block.runs) {
1099
1101
  if (run.text === " ") {
1100
1102
  paragraph.appendTab();
@@ -2607,11 +2609,60 @@ function buildOdtPackage(content) {
2607
2609
  const editor = createOdt();
2608
2610
  content.sections.forEach((section, sectionIndex) => {
2609
2611
  if (sectionIndex > 0) editor.body.appendPageBreak();
2610
- for (const block of section.blocks) appendBlock(editor.body, block);
2612
+ appendBlocks(editor.body, section.blocks);
2611
2613
  });
2612
2614
  return editor.toPackage();
2613
2615
  }
2616
+ function appendBlocks(body, blocks) {
2617
+ let i = 0;
2618
+ while (i < blocks.length) {
2619
+ const block = blocks[i];
2620
+ if (block === void 0) {
2621
+ i++;
2622
+ continue;
2623
+ }
2624
+ if (block.kind === "paragraph" && block.list !== void 0) {
2625
+ const run = [];
2626
+ while (i < blocks.length) {
2627
+ const candidate = blocks[i];
2628
+ if (candidate?.kind !== "paragraph" || candidate.list === void 0) break;
2629
+ run.push(candidate);
2630
+ i++;
2631
+ }
2632
+ appendListRun(body, run);
2633
+ continue;
2634
+ }
2635
+ appendBlock(body, block);
2636
+ i++;
2637
+ }
2638
+ }
2639
+ function appendListRun(body, paragraphs) {
2640
+ let stack = [];
2641
+ let lastItem;
2642
+ let activeNumId;
2643
+ for (const para of paragraphs) {
2644
+ const membership = para.list;
2645
+ if (membership === void 0) continue;
2646
+ if (activeNumId === void 0 || membership.numId !== activeNumId) {
2647
+ stack = [body.appendList()];
2648
+ lastItem = void 0;
2649
+ activeNumId = membership.numId;
2650
+ }
2651
+ const targetLevel = lastItem === void 0 ? 0 : membership.level;
2652
+ while (stack.length - 1 < targetLevel && lastItem !== void 0) {
2653
+ stack.push(lastItem.addNestedList());
2654
+ lastItem = void 0;
2655
+ }
2656
+ while (stack.length - 1 > targetLevel) stack.pop();
2657
+ const currentList = stack[stack.length - 1];
2658
+ if (currentList === void 0) continue;
2659
+ const item = currentList.addItem();
2660
+ populateParagraph(item.appendParagraph(), para);
2661
+ lastItem = item;
2662
+ }
2663
+ }
2614
2664
  function populateParagraph(paragraph, block) {
2665
+ if (block.styleId !== void 0) paragraph.styleId = block.styleId;
2615
2666
  if (block.alignment !== void 0) paragraph.alignment = block.alignment;
2616
2667
  for (const run of block.runs) {
2617
2668
  if (run.text === " ") {
@@ -11476,6 +11527,49 @@ function pdfToOds(bytes, options) {
11476
11527
  }), { signal: options?.signal });
11477
11528
  return (0, odf_js.encodePackage)(buildOdsPackage(content));
11478
11529
  }
11530
+ function odtToDocx(bytes, options) {
11531
+ throwIfAborted(options?.signal);
11532
+ const content = readOdtContent((0, odf_js.decodePackage)(bytes));
11533
+ if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
11534
+ throwIfAborted(options?.signal);
11535
+ return (0, ooxml_js.encodePackage)(buildDocxPackage(content));
11536
+ }
11537
+ function docxToOdt(bytes, options) {
11538
+ throwIfAborted(options?.signal);
11539
+ const content = readDocxContent((0, ooxml_js.decodePackage)(bytes));
11540
+ if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
11541
+ throwIfAborted(options?.signal);
11542
+ return (0, odf_js.encodePackage)(buildOdtPackage(content));
11543
+ }
11544
+ function odpToPptx(bytes, options) {
11545
+ throwIfAborted(options?.signal);
11546
+ const content = readOdpContent((0, odf_js.decodePackage)(bytes));
11547
+ if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
11548
+ throwIfAborted(options?.signal);
11549
+ return (0, ooxml_js.encodePackage)(buildPptxPackage(content));
11550
+ }
11551
+ function pptxToOdp(bytes, options) {
11552
+ throwIfAborted(options?.signal);
11553
+ const content = readPptxContent((0, ooxml_js.decodePackage)(bytes));
11554
+ if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
11555
+ throwIfAborted(options?.signal);
11556
+ return (0, odf_js.encodePackage)(buildOdpPackage(content));
11557
+ }
11558
+ function odsToXlsx(bytes, options) {
11559
+ throwIfAborted(options?.signal);
11560
+ const content = readOdsContent((0, odf_js.decodePackage)(bytes));
11561
+ if (content.kind !== "spreadsheet") throw new Error("readOdsContent returned a non-spreadsheet ContentDocument");
11562
+ throwIfAborted(options?.signal);
11563
+ return (0, ooxml_js.encodePackage)((0, ooxml_js.buildXlsxPackage)(content));
11564
+ }
11565
+ function xlsxToOds(bytes, options) {
11566
+ throwIfAborted(options?.signal);
11567
+ const pkg = (0, ooxml_js.decodePackage)(bytes);
11568
+ const content = (0, ooxml_js.readXlsxContent)(pkg);
11569
+ if (content.kind !== "spreadsheet") throw new Error("readXlsxContent returned a non-spreadsheet ContentDocument");
11570
+ throwIfAborted(options?.signal);
11571
+ return (0, odf_js.encodePackage)(buildOdsPackage(content));
11572
+ }
11479
11573
  //#endregion
11480
11574
  //#region src/convert/codec.ts
11481
11575
  const docxPdfCodec = zod.z.codec(DocxBytesSchema, PdfBytesSchema, {
@@ -11502,6 +11596,18 @@ const odgPdfCodec = zod.z.codec(OdgBytesSchema, PdfBytesSchema, {
11502
11596
  decode: (odgBytes) => odgToPdf(odgBytes),
11503
11597
  encode: (pdfBytes) => pdfToOdg(pdfBytes)
11504
11598
  });
11599
+ const odtDocxCodec = zod.z.codec(OdtBytesSchema, DocxBytesSchema, {
11600
+ decode: (odtBytes) => odtToDocx(odtBytes),
11601
+ encode: (docxBytes) => docxToOdt(docxBytes)
11602
+ });
11603
+ const odpPptxCodec = zod.z.codec(OdpBytesSchema, PptxBytesSchema, {
11604
+ decode: (odpBytes) => odpToPptx(odpBytes),
11605
+ encode: (pptxBytes) => pptxToOdp(pptxBytes)
11606
+ });
11607
+ const odsXlsxCodec = zod.z.codec(OdsBytesSchema, XlsxBytesSchema, {
11608
+ decode: (odsBytes) => odsToXlsx(odsBytes),
11609
+ encode: (xlsxBytes) => xlsxToOds(xlsxBytes)
11610
+ });
11505
11611
  //#endregion
11506
11612
  //#region src/convert/local.ts
11507
11613
  const SUPPORTED_CONVERSIONS = [
@@ -11552,6 +11658,30 @@ const SUPPORTED_CONVERSIONS = [
11552
11658
  {
11553
11659
  source: "pdf",
11554
11660
  target: "odg"
11661
+ },
11662
+ {
11663
+ source: "odt",
11664
+ target: "docx"
11665
+ },
11666
+ {
11667
+ source: "docx",
11668
+ target: "odt"
11669
+ },
11670
+ {
11671
+ source: "odp",
11672
+ target: "pptx"
11673
+ },
11674
+ {
11675
+ source: "pptx",
11676
+ target: "odp"
11677
+ },
11678
+ {
11679
+ source: "ods",
11680
+ target: "xlsx"
11681
+ },
11682
+ {
11683
+ source: "xlsx",
11684
+ target: "ods"
11555
11685
  }
11556
11686
  ];
11557
11687
  function substitutionDiagnostic(substitution, context) {
@@ -11733,6 +11863,66 @@ function createLocalDocumentConverter() {
11733
11863
  diagnostics
11734
11864
  });
11735
11865
  }
11866
+ if (source.format === "odt" && targetFormat === "docx") {
11867
+ const bytes = odtToDocx(source.bytes, { signal: options.signal });
11868
+ return Promise.resolve({
11869
+ document: {
11870
+ format: "docx",
11871
+ bytes
11872
+ },
11873
+ diagnostics
11874
+ });
11875
+ }
11876
+ if (source.format === "docx" && targetFormat === "odt") {
11877
+ const bytes = docxToOdt(source.bytes, { signal: options.signal });
11878
+ return Promise.resolve({
11879
+ document: {
11880
+ format: "odt",
11881
+ bytes
11882
+ },
11883
+ diagnostics
11884
+ });
11885
+ }
11886
+ if (source.format === "odp" && targetFormat === "pptx") {
11887
+ const bytes = odpToPptx(source.bytes, { signal: options.signal });
11888
+ return Promise.resolve({
11889
+ document: {
11890
+ format: "pptx",
11891
+ bytes
11892
+ },
11893
+ diagnostics
11894
+ });
11895
+ }
11896
+ if (source.format === "pptx" && targetFormat === "odp") {
11897
+ const bytes = pptxToOdp(source.bytes, { signal: options.signal });
11898
+ return Promise.resolve({
11899
+ document: {
11900
+ format: "odp",
11901
+ bytes
11902
+ },
11903
+ diagnostics
11904
+ });
11905
+ }
11906
+ if (source.format === "ods" && targetFormat === "xlsx") {
11907
+ const bytes = odsToXlsx(source.bytes, { signal: options.signal });
11908
+ return Promise.resolve({
11909
+ document: {
11910
+ format: "xlsx",
11911
+ bytes
11912
+ },
11913
+ diagnostics
11914
+ });
11915
+ }
11916
+ if (source.format === "xlsx" && targetFormat === "ods") {
11917
+ const bytes = xlsxToOds(source.bytes, { signal: options.signal });
11918
+ return Promise.resolve({
11919
+ document: {
11920
+ format: "ods",
11921
+ bytes
11922
+ },
11923
+ diagnostics
11924
+ });
11925
+ }
11736
11926
  return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
11737
11927
  }
11738
11928
  };
@@ -12030,6 +12220,7 @@ Object.defineProperty(exports, "SLIDE_SIZE_WIDESCREEN", {
12030
12220
  return document_content_model.SLIDE_SIZE_WIDESCREEN;
12031
12221
  }
12032
12222
  });
12223
+ exports.XlsxBytesSchema = XlsxBytesSchema;
12033
12224
  Object.defineProperty(exports, "XmlCdataSchema", {
12034
12225
  enumerable: true,
12035
12226
  get: function() {
@@ -12156,6 +12347,7 @@ Object.defineProperty(exports, "decodePackage", {
12156
12347
  }
12157
12348
  });
12158
12349
  exports.docxPdfCodec = docxPdfCodec;
12350
+ exports.docxToOdt = docxToOdt;
12159
12351
  exports.docxToPdf = docxToPdf;
12160
12352
  Object.defineProperty(exports, "elementsWithTag", {
12161
12353
  enumerable: true,
@@ -12204,10 +12396,16 @@ Object.defineProperty(exports, "isXmlNode", {
12204
12396
  exports.odgPdfCodec = odgPdfCodec;
12205
12397
  exports.odgToPdf = odgToPdf;
12206
12398
  exports.odpPdfCodec = odpPdfCodec;
12399
+ exports.odpPptxCodec = odpPptxCodec;
12207
12400
  exports.odpToPdf = odpToPdf;
12401
+ exports.odpToPptx = odpToPptx;
12208
12402
  exports.odsPdfCodec = odsPdfCodec;
12209
12403
  exports.odsToPdf = odsToPdf;
12404
+ exports.odsToXlsx = odsToXlsx;
12405
+ exports.odsXlsxCodec = odsXlsxCodec;
12406
+ exports.odtDocxCodec = odtDocxCodec;
12210
12407
  exports.odtPdfCodec = odtPdfCodec;
12408
+ exports.odtToDocx = odtToDocx;
12211
12409
  exports.odtToPdf = odtToPdf;
12212
12410
  exports.openDocx = openDocx;
12213
12411
  exports.openOdg = openOdg;
@@ -12241,6 +12439,7 @@ exports.pdfToOds = pdfToOds;
12241
12439
  exports.pdfToOdt = pdfToOdt;
12242
12440
  exports.pdfToPptx = pdfToPptx;
12243
12441
  exports.pptxPdfCodec = pptxPdfCodec;
12442
+ exports.pptxToOdp = pptxToOdp;
12244
12443
  exports.pptxToPdf = pptxToPdf;
12245
12444
  exports.readDocxContent = readDocxContent;
12246
12445
  exports.readOdgContent = readOdgContent;
@@ -12304,6 +12503,7 @@ Object.defineProperty(exports, "walk", {
12304
12503
  }
12305
12504
  });
12306
12505
  exports.writePdf = writePdf;
12506
+ exports.xlsxToOds = xlsxToOds;
12307
12507
  Object.defineProperty(exports, "xmlCodec", {
12308
12508
  enumerable: true,
12309
12509
  get: function() {
package/dist/index.d.cts CHANGED
@@ -368,6 +368,7 @@ declare function flipY(box: Box$1, containerHeightPt: number): Box$1;
368
368
  //#region src/model/bytes.d.ts
369
369
  declare const DocxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
370
370
  declare const PptxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
371
+ declare const XlsxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
371
372
  declare const PdfBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
372
373
  declare const OdtBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
373
374
  declare const OdsBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
@@ -1270,6 +1271,15 @@ declare function pdfToOdt(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumen
1270
1271
  declare function pdfToOdp(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumentOptions): Uint8Array<ArrayBuffer>;
1271
1272
  declare function pdfToOdg(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumentOptions): Uint8Array<ArrayBuffer>;
1272
1273
  declare function pdfToOds(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumentOptions): Uint8Array<ArrayBuffer>;
1274
+ interface DocumentBridgeOptions {
1275
+ readonly signal?: AbortSignal;
1276
+ }
1277
+ declare function odtToDocx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1278
+ declare function docxToOdt(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1279
+ declare function odpToPptx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1280
+ declare function pptxToOdp(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1281
+ declare function odsToXlsx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1282
+ declare function xlsxToOds(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1273
1283
  //#endregion
1274
1284
  //#region src/convert/codec.d.ts
1275
1285
  declare const docxPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
@@ -1278,9 +1288,12 @@ declare const odtPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8
1278
1288
  declare const odpPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1279
1289
  declare const odsPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1280
1290
  declare const odgPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1291
+ declare const odtDocxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1292
+ declare const odpPptxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1293
+ declare const odsXlsxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1281
1294
  //#endregion
1282
1295
  //#region src/convert/port.d.ts
1283
- type DocumentFormat = 'docx' | 'pptx' | 'odt' | 'odp' | 'ods' | 'odg' | 'pdf';
1296
+ type DocumentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'pdf';
1284
1297
  interface DocumentPayload {
1285
1298
  readonly format: DocumentFormat;
1286
1299
  readonly bytes: Uint8Array<ArrayBuffer>;
@@ -1323,4 +1336,4 @@ declare function fixedClock(date: Date): ClockPort;
1323
1336
  //#region src/ports/abort.d.ts
1324
1337
  declare function throwIfAborted(signal: AbortSignal | undefined): void;
1325
1338
  //#endregion
1326
- export { type Alignment, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Box, COLOR_BLACK, CONTENT_FORMAT_VERSION, type ClockPort, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type ContentBlock, ContentBlockSchema, type ContentCellValue, ContentCellValueSchema, type ContentDocument, ContentDocumentSchema, type ContentDrawPage, ContentDrawPageSchema, type ContentImageBlock, ContentImageBlockSchema, type ContentListMembership, type ContentPageBreak, ContentPageBreakSchema, type ContentParagraph, ContentParagraphSchema, type ContentPathPoint, ContentPathPointSchema, type ContentPathSegment, ContentPathSegmentSchema, type ContentRun, ContentRunSchema, type ContentSection, ContentSectionSchema, type ContentShape, ContentShapeSchema, type ContentSheet, type ContentSheetCell, ContentSheetCellSchema, type ContentSheetColumn, ContentSheetColumnSchema, type ContentSheetImage, type ContentSheetPrintRange, ContentSheetPrintRangeSchema, type ContentSheetPrintSettings, ContentSheetPrintSettingsSchema, type ContentSheetRepeatRange, ContentSheetRepeatRangeSchema, type ContentSheetRow, ContentSheetRowSchema, ContentSheetSchema, type ContentSlide, ContentSlideSchema, type ContentStroke, ContentStrokeSchema, type ContentSubpath, ContentSubpathSchema, type ContentTable, type ContentTableCell, ContentTableCellSchema, type ContentTableRow, ContentTableRowSchema, ContentTableSchema, type ContentVector, ContentVectorSchema, type ConversionRequest, type ConversionResult, DEFAULT_LAYOUT_FONT, type DefinedName, DefinedNameSchema, type Diagnostic, type DocumentConverter, type DocumentFormat, type DocumentPayload, type DocumentToPdfOptions, type DocxBody, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, type DrawingLayoutOptions, type DrawingParagraphInit, type DrawingRunInit, type EngineLayoutOptions, LAYOUT_FORMAT_VERSION, type LayoutColor, type LayoutDocument, type LayoutEllipse, type LayoutFont, type LayoutImage, type LayoutImageAsset, type LayoutItem, type LayoutLine, type LayoutLink, type LayoutMetadata, type LayoutPage, type LayoutPath, type LayoutPathSegment, type LayoutRect, type LayoutSubpath, type LayoutText, type Margins, NOOP_DIAGNOSTIC_SINK, OdgBoxVector, type BoxVectorInit as OdgBoxVectorInit, OdgBytesSchema, OdgEditor, OdgLineVector, type LineVectorInit as OdgLineVectorInit, OdgPage, type PageImageInit as OdgPageImageInit, OdgPathVector, type PathVectorInit as OdgPathVectorInit, type TextBoxInit as OdgTextBoxInit, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, type SlideImageInit as OdpSlideImageInit, type TextBoxInit$1 as OdpTextBoxInit, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, type OdtBody, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, type ParagraphInit as OdtParagraphInit, OdtRun, type RunInit as OdtRunInit, OdtTable, OdtTableCell, type TableInit as OdtTableInit, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type Package, PackageSchema, type PageSize, type Part, PartSchema, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, type PdfToDocumentOptions, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, type ReadPdfOptions, type ReconstructOptions, type Relationship, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, type SheetsLayoutOptions, type SlideImageInit$1 as SlideImageInit, type SlidesLayoutOptions, type TextBoxInit$2 as TextBoxInit, type WinAnsiSubstitution, type WritePdfOptions, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdgPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdg, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgPdfCodec, odgToPdf, odpPdfCodec, odpToPdf, odsPdfCodec, odsToPdf, odtPdfCodec, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
1339
+ export { type Alignment, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Box, COLOR_BLACK, CONTENT_FORMAT_VERSION, type ClockPort, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type ContentBlock, ContentBlockSchema, type ContentCellValue, ContentCellValueSchema, type ContentDocument, ContentDocumentSchema, type ContentDrawPage, ContentDrawPageSchema, type ContentImageBlock, ContentImageBlockSchema, type ContentListMembership, type ContentPageBreak, ContentPageBreakSchema, type ContentParagraph, ContentParagraphSchema, type ContentPathPoint, ContentPathPointSchema, type ContentPathSegment, ContentPathSegmentSchema, type ContentRun, ContentRunSchema, type ContentSection, ContentSectionSchema, type ContentShape, ContentShapeSchema, type ContentSheet, type ContentSheetCell, ContentSheetCellSchema, type ContentSheetColumn, ContentSheetColumnSchema, type ContentSheetImage, type ContentSheetPrintRange, ContentSheetPrintRangeSchema, type ContentSheetPrintSettings, ContentSheetPrintSettingsSchema, type ContentSheetRepeatRange, ContentSheetRepeatRangeSchema, type ContentSheetRow, ContentSheetRowSchema, ContentSheetSchema, type ContentSlide, ContentSlideSchema, type ContentStroke, ContentStrokeSchema, type ContentSubpath, ContentSubpathSchema, type ContentTable, type ContentTableCell, ContentTableCellSchema, type ContentTableRow, ContentTableRowSchema, ContentTableSchema, type ContentVector, ContentVectorSchema, type ConversionRequest, type ConversionResult, DEFAULT_LAYOUT_FONT, type DefinedName, DefinedNameSchema, type Diagnostic, type DocumentBridgeOptions, type DocumentConverter, type DocumentFormat, type DocumentPayload, type DocumentToPdfOptions, type DocxBody, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, type DrawingLayoutOptions, type DrawingParagraphInit, type DrawingRunInit, type EngineLayoutOptions, LAYOUT_FORMAT_VERSION, type LayoutColor, type LayoutDocument, type LayoutEllipse, type LayoutFont, type LayoutImage, type LayoutImageAsset, type LayoutItem, type LayoutLine, type LayoutLink, type LayoutMetadata, type LayoutPage, type LayoutPath, type LayoutPathSegment, type LayoutRect, type LayoutSubpath, type LayoutText, type Margins, NOOP_DIAGNOSTIC_SINK, OdgBoxVector, type BoxVectorInit as OdgBoxVectorInit, OdgBytesSchema, OdgEditor, OdgLineVector, type LineVectorInit as OdgLineVectorInit, OdgPage, type PageImageInit as OdgPageImageInit, OdgPathVector, type PathVectorInit as OdgPathVectorInit, type TextBoxInit as OdgTextBoxInit, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, type SlideImageInit as OdpSlideImageInit, type TextBoxInit$1 as OdpTextBoxInit, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, type OdtBody, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, type ParagraphInit as OdtParagraphInit, OdtRun, type RunInit as OdtRunInit, OdtTable, OdtTableCell, type TableInit as OdtTableInit, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type Package, PackageSchema, type PageSize, type Part, PartSchema, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, type PdfToDocumentOptions, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, type ReadPdfOptions, type ReconstructOptions, type Relationship, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, type SheetsLayoutOptions, type SlideImageInit$1 as SlideImageInit, type SlidesLayoutOptions, type TextBoxInit$2 as TextBoxInit, type WinAnsiSubstitution, type WritePdfOptions, XlsxBytesSchema, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdgPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdg, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToOdt, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgPdfCodec, odgToPdf, odpPdfCodec, odpPptxCodec, odpToPdf, odpToPptx, odsPdfCodec, odsToPdf, odsToXlsx, odsXlsxCodec, odtDocxCodec, odtPdfCodec, odtToDocx, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToOdp, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xlsxToOds, xmlCodec, zipPackage };
package/dist/index.d.ts CHANGED
@@ -368,6 +368,7 @@ declare function flipY(box: Box$1, containerHeightPt: number): Box$1;
368
368
  //#region src/model/bytes.d.ts
369
369
  declare const DocxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
370
370
  declare const PptxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
371
+ declare const XlsxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
371
372
  declare const PdfBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
372
373
  declare const OdtBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
373
374
  declare const OdsBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
@@ -1270,6 +1271,15 @@ declare function pdfToOdt(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumen
1270
1271
  declare function pdfToOdp(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumentOptions): Uint8Array<ArrayBuffer>;
1271
1272
  declare function pdfToOdg(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumentOptions): Uint8Array<ArrayBuffer>;
1272
1273
  declare function pdfToOds(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDocumentOptions): Uint8Array<ArrayBuffer>;
1274
+ interface DocumentBridgeOptions {
1275
+ readonly signal?: AbortSignal;
1276
+ }
1277
+ declare function odtToDocx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1278
+ declare function docxToOdt(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1279
+ declare function odpToPptx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1280
+ declare function pptxToOdp(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1281
+ declare function odsToXlsx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1282
+ declare function xlsxToOds(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
1273
1283
  //#endregion
1274
1284
  //#region src/convert/codec.d.ts
1275
1285
  declare const docxPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
@@ -1278,9 +1288,12 @@ declare const odtPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8
1278
1288
  declare const odpPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1279
1289
  declare const odsPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1280
1290
  declare const odgPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1291
+ declare const odtDocxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1292
+ declare const odpPptxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1293
+ declare const odsXlsxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
1281
1294
  //#endregion
1282
1295
  //#region src/convert/port.d.ts
1283
- type DocumentFormat = 'docx' | 'pptx' | 'odt' | 'odp' | 'ods' | 'odg' | 'pdf';
1296
+ type DocumentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'pdf';
1284
1297
  interface DocumentPayload {
1285
1298
  readonly format: DocumentFormat;
1286
1299
  readonly bytes: Uint8Array<ArrayBuffer>;
@@ -1323,4 +1336,4 @@ declare function fixedClock(date: Date): ClockPort;
1323
1336
  //#region src/ports/abort.d.ts
1324
1337
  declare function throwIfAborted(signal: AbortSignal | undefined): void;
1325
1338
  //#endregion
1326
- export { type Alignment, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Box, COLOR_BLACK, CONTENT_FORMAT_VERSION, type ClockPort, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type ContentBlock, ContentBlockSchema, type ContentCellValue, ContentCellValueSchema, type ContentDocument, ContentDocumentSchema, type ContentDrawPage, ContentDrawPageSchema, type ContentImageBlock, ContentImageBlockSchema, type ContentListMembership, type ContentPageBreak, ContentPageBreakSchema, type ContentParagraph, ContentParagraphSchema, type ContentPathPoint, ContentPathPointSchema, type ContentPathSegment, ContentPathSegmentSchema, type ContentRun, ContentRunSchema, type ContentSection, ContentSectionSchema, type ContentShape, ContentShapeSchema, type ContentSheet, type ContentSheetCell, ContentSheetCellSchema, type ContentSheetColumn, ContentSheetColumnSchema, type ContentSheetImage, type ContentSheetPrintRange, ContentSheetPrintRangeSchema, type ContentSheetPrintSettings, ContentSheetPrintSettingsSchema, type ContentSheetRepeatRange, ContentSheetRepeatRangeSchema, type ContentSheetRow, ContentSheetRowSchema, ContentSheetSchema, type ContentSlide, ContentSlideSchema, type ContentStroke, ContentStrokeSchema, type ContentSubpath, ContentSubpathSchema, type ContentTable, type ContentTableCell, ContentTableCellSchema, type ContentTableRow, ContentTableRowSchema, ContentTableSchema, type ContentVector, ContentVectorSchema, type ConversionRequest, type ConversionResult, DEFAULT_LAYOUT_FONT, type DefinedName, DefinedNameSchema, type Diagnostic, type DocumentConverter, type DocumentFormat, type DocumentPayload, type DocumentToPdfOptions, type DocxBody, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, type DrawingLayoutOptions, type DrawingParagraphInit, type DrawingRunInit, type EngineLayoutOptions, LAYOUT_FORMAT_VERSION, type LayoutColor, type LayoutDocument, type LayoutEllipse, type LayoutFont, type LayoutImage, type LayoutImageAsset, type LayoutItem, type LayoutLine, type LayoutLink, type LayoutMetadata, type LayoutPage, type LayoutPath, type LayoutPathSegment, type LayoutRect, type LayoutSubpath, type LayoutText, type Margins, NOOP_DIAGNOSTIC_SINK, OdgBoxVector, type BoxVectorInit as OdgBoxVectorInit, OdgBytesSchema, OdgEditor, OdgLineVector, type LineVectorInit as OdgLineVectorInit, OdgPage, type PageImageInit as OdgPageImageInit, OdgPathVector, type PathVectorInit as OdgPathVectorInit, type TextBoxInit as OdgTextBoxInit, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, type SlideImageInit as OdpSlideImageInit, type TextBoxInit$1 as OdpTextBoxInit, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, type OdtBody, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, type ParagraphInit as OdtParagraphInit, OdtRun, type RunInit as OdtRunInit, OdtTable, OdtTableCell, type TableInit as OdtTableInit, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type Package, PackageSchema, type PageSize, type Part, PartSchema, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, type PdfToDocumentOptions, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, type ReadPdfOptions, type ReconstructOptions, type Relationship, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, type SheetsLayoutOptions, type SlideImageInit$1 as SlideImageInit, type SlidesLayoutOptions, type TextBoxInit$2 as TextBoxInit, type WinAnsiSubstitution, type WritePdfOptions, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdgPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdg, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgPdfCodec, odgToPdf, odpPdfCodec, odpToPdf, odsPdfCodec, odsToPdf, odtPdfCodec, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
1339
+ export { type Alignment, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Box, COLOR_BLACK, CONTENT_FORMAT_VERSION, type ClockPort, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type ContentBlock, ContentBlockSchema, type ContentCellValue, ContentCellValueSchema, type ContentDocument, ContentDocumentSchema, type ContentDrawPage, ContentDrawPageSchema, type ContentImageBlock, ContentImageBlockSchema, type ContentListMembership, type ContentPageBreak, ContentPageBreakSchema, type ContentParagraph, ContentParagraphSchema, type ContentPathPoint, ContentPathPointSchema, type ContentPathSegment, ContentPathSegmentSchema, type ContentRun, ContentRunSchema, type ContentSection, ContentSectionSchema, type ContentShape, ContentShapeSchema, type ContentSheet, type ContentSheetCell, ContentSheetCellSchema, type ContentSheetColumn, ContentSheetColumnSchema, type ContentSheetImage, type ContentSheetPrintRange, ContentSheetPrintRangeSchema, type ContentSheetPrintSettings, ContentSheetPrintSettingsSchema, type ContentSheetRepeatRange, ContentSheetRepeatRangeSchema, type ContentSheetRow, ContentSheetRowSchema, ContentSheetSchema, type ContentSlide, ContentSlideSchema, type ContentStroke, ContentStrokeSchema, type ContentSubpath, ContentSubpathSchema, type ContentTable, type ContentTableCell, ContentTableCellSchema, type ContentTableRow, ContentTableRowSchema, ContentTableSchema, type ContentVector, ContentVectorSchema, type ConversionRequest, type ConversionResult, DEFAULT_LAYOUT_FONT, type DefinedName, DefinedNameSchema, type Diagnostic, type DocumentBridgeOptions, type DocumentConverter, type DocumentFormat, type DocumentPayload, type DocumentToPdfOptions, type DocxBody, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, type DrawingLayoutOptions, type DrawingParagraphInit, type DrawingRunInit, type EngineLayoutOptions, LAYOUT_FORMAT_VERSION, type LayoutColor, type LayoutDocument, type LayoutEllipse, type LayoutFont, type LayoutImage, type LayoutImageAsset, type LayoutItem, type LayoutLine, type LayoutLink, type LayoutMetadata, type LayoutPage, type LayoutPath, type LayoutPathSegment, type LayoutRect, type LayoutSubpath, type LayoutText, type Margins, NOOP_DIAGNOSTIC_SINK, OdgBoxVector, type BoxVectorInit as OdgBoxVectorInit, OdgBytesSchema, OdgEditor, OdgLineVector, type LineVectorInit as OdgLineVectorInit, OdgPage, type PageImageInit as OdgPageImageInit, OdgPathVector, type PathVectorInit as OdgPathVectorInit, type TextBoxInit as OdgTextBoxInit, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, type SlideImageInit as OdpSlideImageInit, type TextBoxInit$1 as OdpTextBoxInit, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, type OdtBody, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, type ParagraphInit as OdtParagraphInit, OdtRun, type RunInit as OdtRunInit, OdtTable, OdtTableCell, type TableInit as OdtTableInit, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type Package, PackageSchema, type PageSize, type Part, PartSchema, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, type PdfToDocumentOptions, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, type ReadPdfOptions, type ReconstructOptions, type Relationship, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, type SheetsLayoutOptions, type SlideImageInit$1 as SlideImageInit, type SlidesLayoutOptions, type TextBoxInit$2 as TextBoxInit, type WinAnsiSubstitution, type WritePdfOptions, XlsxBytesSchema, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdgPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdg, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToOdt, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgPdfCodec, odgToPdf, odpPdfCodec, odpPptxCodec, odpToPdf, odpToPptx, odsPdfCodec, odsToPdf, odsToXlsx, odsXlsxCodec, odtDocxCodec, odtPdfCodec, odtToDocx, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToOdp, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xlsxToOds, xmlCodec, zipPackage };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, PackageSchema, PartSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, elementsWithTag as elementsWithTag$1, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, resolveRelationships, resolveRelationships as resolveRelationships$1, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
1
+ import { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, PackageSchema, PartSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXlsxPackage, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, elementsWithTag as elementsWithTag$1, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, readXlsxContent, resolveRelationships, resolveRelationships as resolveRelationships$1, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
2
2
  import { COLOR_BLACK, ContentBlockSchema, ContentCellValueSchema, ContentDrawPageSchema, ContentDrawPageSchema as ContentDrawPageSchema$1, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentSectionSchema as ContentSectionSchema$1, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSheetSchema as ContentSheetSchema$1, ContentSlideSchema, ContentSlideSchema as ContentSlideSchema$1, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DEFAULT_LAYOUT_FONT, LAYOUT_FORMAT_VERSION, LAYOUT_FORMAT_VERSION as LAYOUT_FORMAT_VERSION$1, LayoutDocumentSchema, LayoutMetadataSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, colorToRgbHex, isContentBlock, rgbHexToColor } from "document-content-model";
3
3
  import { z } from "zod";
4
4
  import { ODF_MEDIA_TYPES, StyleRegistry, applyOdfTransform, base64ToBytes as base64ToBytes$2, buildOdfSubpaths, bytesToBase64 as bytesToBase64$2, decodeOdfText, decodePackage as decodePackage$2, encodePackage as encodePackage$2, findStyleElement, formatOdfColor, formatOdfLength, parseBox, parseCellReference, parseLinePoints, parseMargins, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfViewBox, parsePageSize, readOdg, readOdp, readOds, readOdt, resolveOdfShapeGeometry, resolvePageLayoutProperties, resolveStyle, setDocumentMediaType, syncManifest, syncManifest as syncManifest$1, xmlnsAttributes } from "odf.js";
@@ -79,6 +79,7 @@ function zipBytesSchema(label) {
79
79
  }
80
80
  const DocxBytesSchema = zipBytesSchema("docx");
81
81
  const PptxBytesSchema = zipBytesSchema("pptx");
82
+ const XlsxBytesSchema = zipBytesSchema("xlsx");
82
83
  const PdfBytesSchema = z.instanceof(Uint8Array).refine((bytes) => containsBytesWithin(bytes, PDF_HEADER, PDF_HEADER_SEARCH_WINDOW), { message: "not a valid PDF file: missing the %PDF- header" });
83
84
  const MIMETYPE_ENTRY_FILENAME = "mimetype";
84
85
  const MIMETYPE_FILENAME_OFFSET = 30;
@@ -1094,6 +1095,7 @@ function buildDocxPackage(content) {
1094
1095
  function populateParagraph$1(paragraph, block) {
1095
1096
  paragraph.styleId = block.styleId;
1096
1097
  paragraph.alignment = block.alignment;
1098
+ paragraph.list = block.list;
1097
1099
  for (const run of block.runs) {
1098
1100
  if (run.text === " ") {
1099
1101
  paragraph.appendTab();
@@ -2606,11 +2608,60 @@ function buildOdtPackage(content) {
2606
2608
  const editor = createOdt();
2607
2609
  content.sections.forEach((section, sectionIndex) => {
2608
2610
  if (sectionIndex > 0) editor.body.appendPageBreak();
2609
- for (const block of section.blocks) appendBlock(editor.body, block);
2611
+ appendBlocks(editor.body, section.blocks);
2610
2612
  });
2611
2613
  return editor.toPackage();
2612
2614
  }
2615
+ function appendBlocks(body, blocks) {
2616
+ let i = 0;
2617
+ while (i < blocks.length) {
2618
+ const block = blocks[i];
2619
+ if (block === void 0) {
2620
+ i++;
2621
+ continue;
2622
+ }
2623
+ if (block.kind === "paragraph" && block.list !== void 0) {
2624
+ const run = [];
2625
+ while (i < blocks.length) {
2626
+ const candidate = blocks[i];
2627
+ if (candidate?.kind !== "paragraph" || candidate.list === void 0) break;
2628
+ run.push(candidate);
2629
+ i++;
2630
+ }
2631
+ appendListRun(body, run);
2632
+ continue;
2633
+ }
2634
+ appendBlock(body, block);
2635
+ i++;
2636
+ }
2637
+ }
2638
+ function appendListRun(body, paragraphs) {
2639
+ let stack = [];
2640
+ let lastItem;
2641
+ let activeNumId;
2642
+ for (const para of paragraphs) {
2643
+ const membership = para.list;
2644
+ if (membership === void 0) continue;
2645
+ if (activeNumId === void 0 || membership.numId !== activeNumId) {
2646
+ stack = [body.appendList()];
2647
+ lastItem = void 0;
2648
+ activeNumId = membership.numId;
2649
+ }
2650
+ const targetLevel = lastItem === void 0 ? 0 : membership.level;
2651
+ while (stack.length - 1 < targetLevel && lastItem !== void 0) {
2652
+ stack.push(lastItem.addNestedList());
2653
+ lastItem = void 0;
2654
+ }
2655
+ while (stack.length - 1 > targetLevel) stack.pop();
2656
+ const currentList = stack[stack.length - 1];
2657
+ if (currentList === void 0) continue;
2658
+ const item = currentList.addItem();
2659
+ populateParagraph(item.appendParagraph(), para);
2660
+ lastItem = item;
2661
+ }
2662
+ }
2613
2663
  function populateParagraph(paragraph, block) {
2664
+ if (block.styleId !== void 0) paragraph.styleId = block.styleId;
2614
2665
  if (block.alignment !== void 0) paragraph.alignment = block.alignment;
2615
2666
  for (const run of block.runs) {
2616
2667
  if (run.text === " ") {
@@ -11475,6 +11526,49 @@ function pdfToOds(bytes, options) {
11475
11526
  }), { signal: options?.signal });
11476
11527
  return encodePackage$2(buildOdsPackage(content));
11477
11528
  }
11529
+ function odtToDocx(bytes, options) {
11530
+ throwIfAborted(options?.signal);
11531
+ const content = readOdtContent(decodePackage$2(bytes));
11532
+ if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
11533
+ throwIfAborted(options?.signal);
11534
+ return encodePackage$1(buildDocxPackage(content));
11535
+ }
11536
+ function docxToOdt(bytes, options) {
11537
+ throwIfAborted(options?.signal);
11538
+ const content = readDocxContent(decodePackage$1(bytes));
11539
+ if (content.kind !== "wordprocessing") throw new Error("readDocxContent returned a non-wordprocessing ContentDocument");
11540
+ throwIfAborted(options?.signal);
11541
+ return encodePackage$2(buildOdtPackage(content));
11542
+ }
11543
+ function odpToPptx(bytes, options) {
11544
+ throwIfAborted(options?.signal);
11545
+ const content = readOdpContent(decodePackage$2(bytes));
11546
+ if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
11547
+ throwIfAborted(options?.signal);
11548
+ return encodePackage$1(buildPptxPackage(content));
11549
+ }
11550
+ function pptxToOdp(bytes, options) {
11551
+ throwIfAborted(options?.signal);
11552
+ const content = readPptxContent(decodePackage$1(bytes));
11553
+ if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
11554
+ throwIfAborted(options?.signal);
11555
+ return encodePackage$2(buildOdpPackage(content));
11556
+ }
11557
+ function odsToXlsx(bytes, options) {
11558
+ throwIfAborted(options?.signal);
11559
+ const content = readOdsContent(decodePackage$2(bytes));
11560
+ if (content.kind !== "spreadsheet") throw new Error("readOdsContent returned a non-spreadsheet ContentDocument");
11561
+ throwIfAborted(options?.signal);
11562
+ return encodePackage$1(buildXlsxPackage(content));
11563
+ }
11564
+ function xlsxToOds(bytes, options) {
11565
+ throwIfAborted(options?.signal);
11566
+ const pkg = decodePackage$1(bytes);
11567
+ const content = readXlsxContent(pkg);
11568
+ if (content.kind !== "spreadsheet") throw new Error("readXlsxContent returned a non-spreadsheet ContentDocument");
11569
+ throwIfAborted(options?.signal);
11570
+ return encodePackage$2(buildOdsPackage(content));
11571
+ }
11478
11572
  //#endregion
11479
11573
  //#region src/convert/codec.ts
11480
11574
  const docxPdfCodec = z.codec(DocxBytesSchema, PdfBytesSchema, {
@@ -11501,6 +11595,18 @@ const odgPdfCodec = z.codec(OdgBytesSchema, PdfBytesSchema, {
11501
11595
  decode: (odgBytes) => odgToPdf(odgBytes),
11502
11596
  encode: (pdfBytes) => pdfToOdg(pdfBytes)
11503
11597
  });
11598
+ const odtDocxCodec = z.codec(OdtBytesSchema, DocxBytesSchema, {
11599
+ decode: (odtBytes) => odtToDocx(odtBytes),
11600
+ encode: (docxBytes) => docxToOdt(docxBytes)
11601
+ });
11602
+ const odpPptxCodec = z.codec(OdpBytesSchema, PptxBytesSchema, {
11603
+ decode: (odpBytes) => odpToPptx(odpBytes),
11604
+ encode: (pptxBytes) => pptxToOdp(pptxBytes)
11605
+ });
11606
+ const odsXlsxCodec = z.codec(OdsBytesSchema, XlsxBytesSchema, {
11607
+ decode: (odsBytes) => odsToXlsx(odsBytes),
11608
+ encode: (xlsxBytes) => xlsxToOds(xlsxBytes)
11609
+ });
11504
11610
  //#endregion
11505
11611
  //#region src/convert/local.ts
11506
11612
  const SUPPORTED_CONVERSIONS = [
@@ -11551,6 +11657,30 @@ const SUPPORTED_CONVERSIONS = [
11551
11657
  {
11552
11658
  source: "pdf",
11553
11659
  target: "odg"
11660
+ },
11661
+ {
11662
+ source: "odt",
11663
+ target: "docx"
11664
+ },
11665
+ {
11666
+ source: "docx",
11667
+ target: "odt"
11668
+ },
11669
+ {
11670
+ source: "odp",
11671
+ target: "pptx"
11672
+ },
11673
+ {
11674
+ source: "pptx",
11675
+ target: "odp"
11676
+ },
11677
+ {
11678
+ source: "ods",
11679
+ target: "xlsx"
11680
+ },
11681
+ {
11682
+ source: "xlsx",
11683
+ target: "ods"
11554
11684
  }
11555
11685
  ];
11556
11686
  function substitutionDiagnostic(substitution, context) {
@@ -11732,6 +11862,66 @@ function createLocalDocumentConverter() {
11732
11862
  diagnostics
11733
11863
  });
11734
11864
  }
11865
+ if (source.format === "odt" && targetFormat === "docx") {
11866
+ const bytes = odtToDocx(source.bytes, { signal: options.signal });
11867
+ return Promise.resolve({
11868
+ document: {
11869
+ format: "docx",
11870
+ bytes
11871
+ },
11872
+ diagnostics
11873
+ });
11874
+ }
11875
+ if (source.format === "docx" && targetFormat === "odt") {
11876
+ const bytes = docxToOdt(source.bytes, { signal: options.signal });
11877
+ return Promise.resolve({
11878
+ document: {
11879
+ format: "odt",
11880
+ bytes
11881
+ },
11882
+ diagnostics
11883
+ });
11884
+ }
11885
+ if (source.format === "odp" && targetFormat === "pptx") {
11886
+ const bytes = odpToPptx(source.bytes, { signal: options.signal });
11887
+ return Promise.resolve({
11888
+ document: {
11889
+ format: "pptx",
11890
+ bytes
11891
+ },
11892
+ diagnostics
11893
+ });
11894
+ }
11895
+ if (source.format === "pptx" && targetFormat === "odp") {
11896
+ const bytes = pptxToOdp(source.bytes, { signal: options.signal });
11897
+ return Promise.resolve({
11898
+ document: {
11899
+ format: "odp",
11900
+ bytes
11901
+ },
11902
+ diagnostics
11903
+ });
11904
+ }
11905
+ if (source.format === "ods" && targetFormat === "xlsx") {
11906
+ const bytes = odsToXlsx(source.bytes, { signal: options.signal });
11907
+ return Promise.resolve({
11908
+ document: {
11909
+ format: "xlsx",
11910
+ bytes
11911
+ },
11912
+ diagnostics
11913
+ });
11914
+ }
11915
+ if (source.format === "xlsx" && targetFormat === "ods") {
11916
+ const bytes = xlsxToOds(source.bytes, { signal: options.signal });
11917
+ return Promise.resolve({
11918
+ document: {
11919
+ format: "ods",
11920
+ bytes
11921
+ },
11922
+ diagnostics
11923
+ });
11924
+ }
11735
11925
  return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
11736
11926
  }
11737
11927
  };
@@ -11743,4 +11933,4 @@ function fixedClock(date) {
11743
11933
  return { now: () => date };
11744
11934
  }
11745
11935
  //#endregion
11746
- export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentDrawPageSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBoxVector, OdgBytesSchema, OdgEditor, OdgLineVector, OdgPage, OdgPathVector, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, OdtRun, OdtTable, OdtTableCell, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdgPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdg, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgPdfCodec, odgToPdf, odpPdfCodec, odpToPdf, odsPdfCodec, odsToPdf, odtPdfCodec, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
11936
+ export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentCellValueSchema, ContentDocumentSchema, ContentDrawPageSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentStrokeSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBoxVector, OdgBytesSchema, OdgEditor, OdgLineVector, OdgPage, OdgPathVector, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, OdsCell, OdsEditor, OdsSheet, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, OdtRun, OdtTable, OdtTableCell, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XlsxBytesSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdgPackage, buildOdpPackage, buildOdsPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertDrawingToLayout, convertPresentationToLayout, convertSpreadsheetToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdg, createOdp, createOds, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToOdt, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odgPdfCodec, odgToPdf, odpPdfCodec, odpPptxCodec, odpToPdf, odpToPptx, odsPdfCodec, odsToPdf, odsToXlsx, odsXlsxCodec, odtDocxCodec, odtPdfCodec, odtToDocx, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToOdp, pptxToPdf, readDocxContent, readOdgContent, readOdpContent, readOdsContent, readOdtContent, readPdf, readPptxContent, reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xlsxToOds, xmlCodec, zipPackage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "documents.js",
3
- "version": "1.48.0",
3
+ "version": "1.49.0",
4
4
  "description": "Bidirectional docx/pptx <-> PDF conversion and a read+write editable OOXML document model, built on ooxml.js and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -67,7 +67,7 @@
67
67
  "document-content-model": "^1.3.0",
68
68
  "fflate": "^0.8.3",
69
69
  "odf.js": "^1.8.0",
70
- "ooxml.js": "^2.1.0",
70
+ "ooxml.js": "^2.2.0",
71
71
  "zod": "^4.4.3"
72
72
  },
73
73
  "devDependencies": {