js.documents 2.0.0 → 2.1.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.
Files changed (54) hide show
  1. package/README.md +34 -28
  2. package/dist/codecs/registry.cjs +7 -0
  3. package/dist/codecs/registry.js +7 -0
  4. package/dist/convert/capability.cjs +5 -0
  5. package/dist/convert/capability.js +5 -0
  6. package/dist/convert/codec.cjs +20 -0
  7. package/dist/convert/codec.d.cts +5 -1
  8. package/dist/convert/codec.d.ts +5 -1
  9. package/dist/convert/codec.js +19 -3
  10. package/dist/convert/composition.cjs +32 -7
  11. package/dist/convert/composition.d.cts +9 -5
  12. package/dist/convert/composition.d.ts +9 -5
  13. package/dist/convert/composition.js +32 -7
  14. package/dist/convert/convert.cjs +32 -0
  15. package/dist/convert/convert.d.cts +18 -1
  16. package/dist/convert/convert.d.ts +18 -1
  17. package/dist/convert/convert.js +25 -1
  18. package/dist/convert/local.cjs +2 -0
  19. package/dist/convert/local.js +2 -0
  20. package/dist/convert/port.cjs +1 -0
  21. package/dist/convert/port.d.cts +3 -0
  22. package/dist/convert/port.d.ts +3 -0
  23. package/dist/convert/port.js +1 -0
  24. package/dist/csv/read.cjs +85 -0
  25. package/dist/csv/read.d.cts +10 -0
  26. package/dist/csv/read.d.ts +10 -0
  27. package/dist/csv/read.js +84 -0
  28. package/dist/csv/records.cjs +85 -0
  29. package/dist/csv/records.d.cts +10 -0
  30. package/dist/csv/records.d.ts +10 -0
  31. package/dist/csv/records.js +80 -0
  32. package/dist/csv/text.cjs +22 -0
  33. package/dist/csv/text.d.cts +8 -0
  34. package/dist/csv/text.d.ts +8 -0
  35. package/dist/csv/text.js +19 -0
  36. package/dist/csv/write.cjs +75 -0
  37. package/dist/csv/write.d.cts +22 -0
  38. package/dist/csv/write.d.ts +22 -0
  39. package/dist/csv/write.js +71 -0
  40. package/dist/index.cjs +27 -1
  41. package/dist/index.d.cts +9 -5
  42. package/dist/index.d.ts +9 -5
  43. package/dist/index.js +9 -5
  44. package/dist/layout/reconstruct.cjs +1 -1
  45. package/dist/layout/reconstruct.js +1 -1
  46. package/dist/metadata/write.cjs +1 -0
  47. package/dist/metadata/write.js +1 -0
  48. package/dist/model/bytes.cjs +2 -0
  49. package/dist/model/bytes.d.cts +2 -1
  50. package/dist/model/bytes.d.ts +2 -1
  51. package/dist/model/bytes.js +2 -1
  52. package/dist/odb/csv.cjs +3 -6
  53. package/dist/odb/csv.js +3 -6
  54. package/package.json +1 -1
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
- > Converts between any two compatible document formats through a shared content/layout pivot. docx, pptx, odt, odp, ods, odg, xlsx, and markdown all read into and build from the same `ContentDocument`/`LayoutDocument` model, with PDF as the one format every variant can reach. A composition engine (`convertDocument`) routes 73 (source, target) pairs across the eight content formats and PDF, including fourteen PDF-pivot round trips, sixteen cross-format bridges (same-variant direct copies, cross-variant semantic transforms, and PDF-composed), plus special-case conversions for `.odm` master documents, `.odb` database front-ends (HSQLDB and Firebird, four storage tiers), standalone `.odf` formula documents, and a bounded SQL/rpt-formula engine for `.odb` reports. Also includes: read-and-write live-view editors for all six editable formats, docx comment/footnote/header-footer exposure via `readDocxExtras`, real font resolution (source-embedded faces ahead of caller-supplied, vendored substitutes, and the standard 14), a hand-written MathML typesetting engine with embedded-font PDF rendering and a matching MathML ⇄ OMML translator, and a fully hand-written PDF codec. Built on [ooxml.js](https://github.com/ExaDev/ooxml.js), [odf.js](https://github.com/ExaDev/odf.js), [pdf-codec](https://github.com/ExaDev/pdf-codec), [markdown-codec](https://github.com/ExaDev/markdown-codec), and [document-schema.js](https://github.com/ExaDev/document-schema.js).
5
+ > Converts between any two compatible document formats through a shared content/layout pivot. docx, pptx, odt, odp, ods, odg, xlsx, csv (TSV is the same format with a tab delimiter), and markdown all read into and build from the same `ContentDocument`/`LayoutDocument` model, with PDF as the one format every variant can reach. A composition engine (`convertDocument`) routes 91 (source, target) pairs across the nine content formats and PDF, including eighteen PDF-pivot round trips (the seven layout-engine formats, plus xlsx and csv composing through ods), twenty-two cross-format bridge functions (same-variant direct copies, cross-variant semantic transforms, and PDF-composed), plus special-case conversions for `.odm` master documents, `.odb` database front-ends (HSQLDB and Firebird, four storage tiers), standalone `.odf` formula documents, and a bounded SQL/rpt-formula engine for `.odb` reports. Also includes: read-and-write live-view editors for all six editable formats, docx comment/footnote/header-footer exposure via `readDocxExtras`, real font resolution (source-embedded faces ahead of caller-supplied, vendored substitutes, and the standard 14), a hand-written MathML typesetting engine with embedded-font PDF rendering and a matching MathML ⇄ OMML translator, and a fully hand-written PDF codec. Built on [ooxml.js](https://github.com/ExaDev/ooxml.js), [odf.js](https://github.com/ExaDev/odf.js), [pdf-codec](https://github.com/ExaDev/pdf-codec), [markdown-codec](https://github.com/ExaDev/markdown-codec), and [document-schema.js](https://github.com/ExaDev/document-schema.js).
6
6
 
7
7
  `documents.js` extends `ooxml.js` in two directions `ooxml.js` deliberately does not cover: full PDF support (parsing and generating, via `pdf-codec`), and a read-**and-write** manipulation API for docx/pptx content — `ooxml.js`'s own typed readers are one-way. The PDF codec is hand-written against ISO 32000-1, with no external PDF library as a dependency — see [Fidelity](#fidelity) and pdf-codec's own README for the honest trade-off (not as robust against adversarial PDFs as a 15+-year-hardened library; fully auditable and dependency-free instead). `src/mathml/` (the MathML typesetting engine) stays in this package and is hand-written too, for the same supply-chain reason.
8
8
 
@@ -72,7 +72,7 @@ npm install documents.js
72
72
 
73
73
  ### The generic entry point: `convertDocument`
74
74
 
75
- A single function, `convertDocument`, sits behind every named conversion and reaches every pair the composition engine can route — all 73 supported (source, target) combinations. The named functions below are thin one-line forwarders to it; they remain the ergonomic layer for a caller who wants a fixed pair and autocomplete discovery, while `convertDocument` is the first-class entry point for a caller working from a runtime format pair (CLI, MCP tool, matrix enumeration).
75
+ A single function, `convertDocument`, sits behind every named conversion and reaches every pair the composition engine can route — all 91 supported (source, target) combinations. The named functions below are thin one-line forwarders to it; they remain the ergonomic layer for a caller who wants a fixed pair and autocomplete discovery, while `convertDocument` is the first-class entry point for a caller working from a runtime format pair (CLI, MCP tool, matrix enumeration).
76
76
 
77
77
  ```ts
78
78
  import { convertDocument } from 'documents.js';
@@ -89,10 +89,10 @@ const odtBytes = convertDocument('docx', 'odt', docxBytes, { onMathDiagnostic: (
89
89
 
90
90
  ### PDF-pivot conversions
91
91
 
92
- The fourteen round-trip ergonomic conversions between the formats with their own layout engine and PDF (docx/pptx/odt/odp/ods/odg/markdown ⇄ PDF, all round-tripping both ways), plus `xlsxToPdf`/`pdfToXlsx` (composing the ods⇄xlsx bridge with the ods⇄pdf layout pair internally):
92
+ The fourteen round-trip ergonomic conversions between the formats with their own layout engine and PDF (docx/pptx/odt/odp/ods/odg/markdown ⇄ PDF, all round-tripping both ways), plus `xlsxToPdf`/`pdfToXlsx` and `csvToPdf`/`pdfToCsv` (each composing its ods bridge with the ods⇄pdf layout pair internally — neither xlsx nor csv has a layout engine of its own):
93
93
 
94
94
  ```ts
95
- import { docxToPdf, markdownToPdf, odgToPdf, odpToPdf, odsToPdf, odtToPdf, pdfToDocx, pdfToMarkdown, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pdfToXlsx, pptxToPdf, xlsxToPdf } from 'documents.js';
95
+ import { csvToPdf, docxToPdf, markdownToPdf, odgToPdf, odpToPdf, odsToPdf, odtToPdf, pdfToCsv, pdfToDocx, pdfToMarkdown, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pdfToXlsx, pptxToPdf, xlsxToPdf } from 'documents.js';
96
96
 
97
97
  const pdfBytes = docxToPdf(docxBytes);
98
98
  const docxBytes2 = pdfToDocx(pdfBytes);
@@ -117,13 +117,16 @@ const xlsxBytes2 = pdfToXlsx(pdfFromXlsx); // composes pdfToOds -> odsToXlsx int
117
117
 
118
118
  const pdfFromMarkdown = markdownToPdf(markdownBytes);
119
119
  const markdownBytes2 = pdfToMarkdown(pdfFromMarkdown); // the lossiest conversion in the whole package -- see Fidelity
120
+
121
+ const pdfFromCsv = csvToPdf(csvBytes); // composes csvToOds -> odsToPdf internally
122
+ const csvBytes2 = pdfToCsv(pdfFromCsv); // composes pdfToOds -> odsToCsv internally; recovers what was printed, then heuristically re-types it
120
123
  ```
121
124
 
122
125
  Each accepts an optional `signal` (`AbortSignal`) and either `onSubstitution` (X → PDF, called per character not representable in a standard-14 font) or `sink` (PDF → X, called per recoverable parse diagnostic). Every X → PDF conversion additionally accepts `fonts` (extra `ProvidedFont` faces) and `onFontSubstitution` (per family+weight+style that resolved to something else). Neither is needed for the common case — see [Fonts](#fonts).
123
126
 
124
127
  ### Cross-format bridges
125
128
 
126
- Sixteen bridge functions across eight pairs bypass the PDF pivot entirely. Five same-variant direct-copy pairs (`odtToDocx`/`docxToOdt`, `odpToPptx`/`pptxToOdp`, `odsToXlsx`/`xlsxToOds`, `markdownToDocx`/`docxToMarkdown`, `markdownToOdt`/`odtToMarkdown`) compose a direct `readXContent` → `buildYPackage` pivot copy. Two cross-variant semantic-transform pairs (`docxToPptx`/`pptxToDocx`, `odtToOdp`/`odpToOdt`) go through `src/convert/variant-bridges.ts`. One PDF-composed pair (`xlsxToMarkdown`/`markdownToXlsx`) routes through PDF internally — the single lossiest conversion in the package.
129
+ Twenty-two bridge functions across eleven pairs bypass the PDF pivot where a direct path exists. Seven same-variant direct-copy pairs (`odtToDocx`/`docxToOdt`, `odpToPptx`/`pptxToOdp`, `odsToXlsx`/`xlsxToOds`, `csvToOds`/`odsToCsv`, `csvToXlsx`/`xlsxToCsv`, `markdownToDocx`/`docxToMarkdown`, `markdownToOdt`/`odtToMarkdown`) compose a direct `readXContent` → `buildYPackage` pivot copy — the csv pairs are one hop to its spreadsheet siblings, so csv never needs PDF to reach ods or xlsx. Two cross-variant semantic-transform pairs (`docxToPptx`/`pptxToDocx`, `odtToOdp`/`odpToOdt`) go through `src/convert/variant-bridges.ts`. Two PDF-composed pairs (`xlsxToMarkdown`/`markdownToXlsx`, `csvToMarkdown`/`markdownToCsv`) route through PDF internally — the lossiest conversions in the package.
127
130
 
128
131
  ```ts
129
132
  import { odtToDocx, docxToOdt, markdownToDocx, docxToMarkdown } from 'documents.js';
@@ -135,7 +138,7 @@ const docxFromMarkdown = markdownToDocx(markdownBytes);
135
138
  const markdownBytes3 = docxToMarkdown(docxFromMarkdown); // colour, font family/size, and explicit alignment have no markdown source construct -- dropped on this hop
136
139
  ```
137
140
 
138
- Each takes an optional `{ signal }` — no `onSubstitution`/`sink`, since there is no font substitution or PDF-parse degradation. `odtToDocx`/`markdownToDocx`/`docxToOdt`/`docxToMarkdown` additionally take `onMathDiagnostic`, called per formula construct that degraded crossing the bridge.
141
+ Each takes an optional `{ signal }` — no `onSubstitution`/`sink`, since there is no font substitution or PDF-parse degradation. `odtToDocx`/`markdownToDocx`/`docxToOdt`/`docxToMarkdown` additionally take `onMathDiagnostic`, called per formula construct that degraded crossing the bridge. The csv-sourced bridges (`csvToOds`, `csvToXlsx`, `csvToMarkdown`, `csvToPdf`) take `{ delimiter }` — `'\t'` parses the same format as TSV, since a delimiter is a parse option, not a different document format — and `onCellTypeInference`, the per-decision audit channel the read shares with `pdfToOds`. The csv-target bridges (`odsToCsv`, `xlsxToCsv`, `markdownToCsv`, `pdfToCsv`) take `{ delimiter, sheet }`: csv has no second sheet, so writing a multi-sheet source refuses with `CsvSheetNotSpecifiedError` naming every sheet until a caller selects one.
139
142
 
140
143
  ### The `DocumentConverter` port
141
144
 
@@ -151,12 +154,12 @@ const { document, diagnostics } = await converter.convert(
151
154
  );
152
155
  ```
153
156
 
154
- `DocumentFormat` includes `docx`/`pptx`/`xlsx`/`odt`/`odp`/`ods`/`odg`/`odf`/`markdown`/`pdf` — ten members. The port's `conversions` list is derived from `resolveCompositionPlan` plus the `odf`→`pdf` special case — 73 pairs total. `DocumentFormat` is inferred from `DocumentFormatSchema` (a real Zod schema); `DOCUMENT_FORMATS` is exported as a plain array derived from the same schema:
157
+ `DocumentFormat` includes `docx`/`pptx`/`xlsx`/`odt`/`odp`/`ods`/`odg`/`odf`/`csv`/`markdown`/`pdf` — eleven members. The port's `conversions` list is derived from `resolveCompositionPlan` plus the `odf`→`pdf` special case — 91 pairs total. `DocumentFormat` is inferred from `DocumentFormatSchema` (a real Zod schema); `DOCUMENT_FORMATS` is exported as a plain array derived from the same schema:
155
158
 
156
159
  ```ts
157
160
  import { DOCUMENT_FORMATS, DocumentFormatSchema } from 'documents.js';
158
161
 
159
- console.log(DOCUMENT_FORMATS); // ['docx', 'pptx', 'xlsx', 'odt', 'odp', 'ods', 'odg', 'odf', 'markdown', 'pdf']
162
+ console.log(DOCUMENT_FORMATS); // ['docx', 'pptx', 'xlsx', 'odt', 'odp', 'ods', 'odg', 'odf', 'csv', 'markdown', 'pdf']
160
163
  DocumentFormatSchema.parse(userSuppliedFormat); // throws a ZodError for anything outside that list
161
164
  ```
162
165
 
@@ -202,7 +205,7 @@ const docxBytesAgain = buildDocumentBytes(captured, 'docx');
202
205
 
203
206
  ### Package decode/encode, metadata, and deep imports
204
207
 
205
- `decodeDocumentPackage`/`encodeDocumentPackage` dispatch docx/pptx/xlsx through `ooxml.js`'s OPC codec and odt/odp/ods/odg/odf through `odf.js`'s ODF codec, throwing `UnsupportedPackageFormatError` for `markdown`/`pdf`. `decodeOdbPackage` is the `.odb`-specific sibling (`.odb` is not a `DocumentFormat` member):
208
+ `decodeDocumentPackage`/`encodeDocumentPackage` dispatch docx/pptx/xlsx through `ooxml.js`'s OPC codec and odt/odp/ods/odg/odf through `odf.js`'s ODF codec, throwing `UnsupportedPackageFormatError` for `markdown`/`csv`/`pdf` (none of the three is a package — they are plain text and bytes respectively). `decodeOdbPackage` is the `.odb`-specific sibling (`.odb` is not a `DocumentFormat` member):
206
209
 
207
210
  ```ts
208
211
  import { decodeDocumentPackage, decodeOdbPackage, encodeDocumentPackage } from 'documents.js';
@@ -212,7 +215,7 @@ const docxBytesAgain = encodeDocumentPackage('docx', pkg);
212
215
  const odbPkg = decodeOdbPackage(odbBytes);
213
216
  ```
214
217
 
215
- `readDocumentMetadata`/`setDocumentMetadata` read or patch metadata across any `DocumentFormat`. `setDocumentMetadata` patches in place (source/target formats must match); `odf` is rejected in both directions. `readDocumentMetadata('xlsx', ...)` is a named exception: it renders via `xlsxToPdf` and reads the PDF's metadata, because a direct read and the PDF-preview path genuinely disagree on `createdIso`/`modifiedIso`/`producer`.
218
+ `readDocumentMetadata`/`setDocumentMetadata` read or patch metadata across any `DocumentFormat`. `setDocumentMetadata` patches in place (source/target formats must match); `odf` is rejected in both directions, and `csv` is rejected in both directions too (RFC 4180 text has no metadata container) — `readDocumentMetadata('csv', ...)` answers an empty `LayoutMetadata` for the same reason. `readDocumentMetadata('xlsx', ...)` is a named exception: it renders via `xlsxToPdf` and reads the PDF's metadata, because a direct read and the PDF-preview path genuinely disagree on `createdIso`/`modifiedIso`/`producer`.
216
219
 
217
220
  ```ts
218
221
  import { readDocumentMetadata, setDocumentMetadata } from 'documents.js';
@@ -230,7 +233,7 @@ import { buildOdtPackage } from 'documents.js/edit/odt/content';
230
233
 
231
234
  ### Reading and building xlsx content directly
232
235
 
233
- Every other content format has its own standalone `readXContent`-shaped entry point (`readDocxContent`, `readPptxContent`, `readOdtContent`, `readOdpContent`, `readOdsContent`, `readOdgContent`) — xlsx is no longer the exception. `readXlsxContent`/`buildXlsxPackage` are `ooxml.js`'s own spreadsheet `ContentDocument` read/build pair — the same one the `ods⇄xlsx` bridge and every xlsx metadata-rebuild path already use internally — re-exported here directly rather than wrapped, since `readXlsxContent` already produces the right shape on its own:
236
+ Every other content format has its own standalone `readXContent`-shaped entry point (`readDocxContent`, `readPptxContent`, `readOdtContent`, `readOdpContent`, `readOdsContent`, `readOdgContent`) — xlsx is no longer the exception. `readXlsxContent`/`buildXlsxPackage` are `ooxml.js`'s own spreadsheet `ContentDocument` read/build pair — the same one the `ods⇄xlsx` bridge and every xlsx metadata-rebuild path already use internally — re-exported here directly rather than wrapped, since `readXlsxContent` already produces the right shape on its own. csv's `readCsvContent`/`buildCsvText` are the same kind of directly-exported stage pair, one level further in: they operate on RFC 4180 text rather than a decoded package (see `src/csv/` under Architecture).
234
237
 
235
238
  ```ts
236
239
  import { buildXlsxPackage, decodeDocumentPackage, encodeDocumentPackage, readXlsxContent } from 'documents.js';
@@ -326,7 +329,7 @@ const layout = readPdf(pdfBytes); // -> LayoutDocument: pages of positioned text
326
329
  const bytes = writePdf(layout);
327
330
  ```
328
331
 
329
- The nine PDF round trips and ten PDF-bypassing bridges are also available as schema-validated [`z.codec()`](https://zod.dev) pairs (`pdfCodec`, `docxPdfCodec`, `pptxPdfCodec`, `odtPdfCodec`, `odpPdfCodec`, `odsPdfCodec`, `odgPdfCodec`, `xlsxPdfCodec`, `markdownPdfCodec`, `odtDocxCodec`, `odpPptxCodec`, `odsXlsxCodec`, `markdownDocxCodec`, `markdownOdtCodec`) — the no-options form, adding automatic two-way schema validation:
332
+ The ten PDF round trips and fourteen PDF-bypassing bridge directions are also available as schema-validated [`z.codec()`](https://zod.dev) pairs (`pdfCodec`, `docxPdfCodec`, `pptxPdfCodec`, `odtPdfCodec`, `odpPdfCodec`, `odsPdfCodec`, `odgPdfCodec`, `xlsxPdfCodec`, `csvPdfCodec`, `markdownPdfCodec`, `odtDocxCodec`, `odpPptxCodec`, `odsXlsxCodec`, `odsCsvCodec`, `xlsxCsvCodec`, `markdownDocxCodec`, `markdownOdtCodec`) — the no-options form, adding automatic two-way schema validation. The two PDF-composed pairs have codec forms too (`xlsxMarkdownCodec`, `csvMarkdownCodec`):
330
333
 
331
334
  ```ts
332
335
  import { z } from 'zod';
@@ -504,6 +507,7 @@ The package is layered from generic primitives outward to the two conversion dir
504
507
  - **`src/ooxml/`** — thin adapters over `ooxml.js`'s own `readDocx`/`readPptx`, wrapping results into `ContentDocument`. `docx/formula.ts` is the one local reading pass (splicing OOXML math equations). `docx/extras.ts`'s `readDocxExtras` returns comments/footnotes/headers/footers/numbering.
505
508
  - **`src/odf/`** — ODF-side counterparts: `readOdtContent`/`readOdpContent`/`readOdsContent`/`readOdgContent` are thin adapters over `odf.js`. `formula/read.ts`/`formula/detect.ts` handle embedded formula detection (genuinely new work with no `odf.js`-side equivalent).
506
509
  - **`src/markdown/`** — third adapter family, via `markdown-codec`. `readMarkdownContent` passes `readMarkdown`'s result straight through (it already produces a full `ContentDocument`). `buildMarkdownText` wraps `writeMarkdown`. `text.ts` is the byte↔text boundary. `MarkdownEditor` holds a mutable in-memory `ContentDocument`.
510
+ - **`src/csv/`** — fourth adapter family, sharing the spreadsheet variant with xlsx/ods. `records.ts` is the RFC 4180 record parser/writer (one shared `quoteCsvField`, also used by the `.odb` CSV exporter); `text.ts` is the byte↔text boundary, rejecting malformed UTF-8; `read.ts` turns records into a spreadsheet `ContentDocument` (first record as verbatim string header, data cells through the same cell-typing heuristic `pdfToOds` uses); `write.ts` turns one sheet of a spreadsheet `ContentDocument` back into records via each cell's `displayText`. TSV is the same format with `{ delimiter: '\t' }` on either side.
507
511
  - **`src/layout/`** — the pure conversion algorithms: `engine.ts` (wordprocessing → layout: flow, line-breaking, pagination), `slides.ts` (presentation → layout: direct placement), `sheets.ts` (spreadsheet → layout: grid, print settings, the first algorithm accepting `AbortSignal`), `drawing.ts` (drawing → layout: vector primitives + shape reuse), `reconstruct.ts` (layout → content: baseline clustering for wordprocessing/presentation, near-1:1 mapping for drawing, gridline-lattice-or-text-clustering for spreadsheet).
508
512
  - **`src/hsqldb/`** — `.odb` decoders, four tiers: `script.ts` (TEXT-script DDL/DML parser), `rowformat.ts`/`cache.ts` (CACHED binary row-store), `binary-script.ts` (BINARY/COMPRESSED whole-script). All import only `document-schema.js` — no odf.js knowledge.
509
513
  - **`src/firebird/`** — Tier 3: gbak logical-backup reader. `reader.ts` (attribute framing + RLE decompression + XDR decoding), `schema.ts`/`data.ts` (table/row walking). No ratified spec — built against Firebird's own engine source.
@@ -550,6 +554,7 @@ To run a single test file: `pnpm vitest run src/path/to/file.test.ts`.
550
554
  - **ODF text getters must call `decodeOdfText`.** See the dedicated gotcha above.
551
555
  - **`readPdf` recovers rect/ellipse/line as their own `LayoutRect`/`LayoutEllipse`/`LayoutLine` kinds** via pdf-codec's shape-pattern detection — an axis-aligned closed four-corner subpath is a rect, four kappa-ratio cubics at cardinal points is an ellipse, an open single straight stroke is a line. A false positive changes kind, never geometry. Off-axis rotations, freeform curves, and multi-subpath figures narrow to `LayoutPath`.
552
556
  - **`pdfToOds` re-types cells heuristically — this is probabilistic, not a fidelity guarantee.** A rendered PDF never carries a cell's typed value, only the printed string. Re-typing fires only where the string has exactly one defensible reading: the decimal must be exactly representable as a JS number; separators must be unambiguous (`"1,234"` is declined — competing European reading is 1.234); leading zeros decline (`"007"`); dates must self-state their component roles (ISO or named month accepted; `"01/02/2024"` declined). `TRUE`/`FALSE` re-type as booleans; `Yes`/`No` are declined. `displayText` always carries the rendered string verbatim. `onCellTypeInference` reports every decision. A formula is never claimed.
557
+ - **The csv read shares `pdfToOds`'s cell-typing heuristic, with the same decision-only audit channel.** The first record is a verbatim string header (never re-typed, even when it looks like data); data cells re-type through `inferCellValue` exactly as the PDF reconstructor does — declines keep the plain string, `displayText` always carries the raw field text, and `onCellTypeInference` fires per decision, staying silent for header cells and no-candidate text. The parser drops blank records, so a record of one empty field alone cannot round-trip. Writing csv takes exactly one sheet: a multi-sheet source refuses with `CsvSheetNotSpecifiedError` naming every sheet until `{ sheet }` selects one. TSV is not a separate format — `{ delimiter: '\t' }` on either side parses or writes the same grid.
553
558
  - **`reconstructWordprocessing`/`reconstructPresentation` recover vector primitives too**, in a nested drawing document — a rule under a heading, an underline, a cell background are all recovered as vectors (intended — discarding real content because it might be incidental is ruled out). A table's gridlines are excluded from vector recovery when the lattice claims them.
554
559
  - **Recovered vectors round-trip through all four readers** — `buildDocxPackage`/`buildPptxPackage` write real DrawingML; `buildOdtPackage`/`buildOdpPackage` write real `draw:rect`/`draw:ellipse`/`draw:line`/`draw:path`. The six PDF-bypassing bridges carry vector geometry across too.
555
560
  - **Each format wraps a vector shape differently.** OOXML: pptx gets a plain `p:sp`; docx gets a `w:drawing`/`wp:anchor` with `behindDoc="1"`/`wp:wrapNone` carrying a `wps:wsp`. ODF: odp appends to `draw:page`; odt anchors in a `text:p` with `style:horizontal-rel`/`style:vertical-rel="page"` (page-absolute coordinates) and `style:run-through="background"`.
@@ -618,20 +623,21 @@ To run a single test file: `pnpm vitest run src/path/to/file.test.ts`.
618
623
 
619
624
  Read as **row → column**. `✓` lossless, `~` bounded, `✗` lossy, `✗✗` severe, `→` one-way, `–` no conversion. `.odm`/`.odb` sit outside this table.
620
625
 
621
- | ↓ from \ to → | docx | pptx | xlsx | odt | odp | ods | odg | odf | markdown | pdf |
622
- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
623
- | **docx** | — | ~ | – | ✓ | – | – | – | – | ✗ | ~ |
624
- | **pptx** | ~ | — | – | – | ✓ | – | – | – | – | ~ |
625
- | **xlsx** | – | – | — | – | – | ~ | – | – | ✗✗ | ~ |
626
- | **odt** | ✓ | – | – | — | ~ | – | – | – | ✗ | ~ |
627
- | **odp** | – | ✓ | – | ~ | — | – | – | – | – | ~ |
628
- | **ods** | – | – | ~ | – | – | — | – | – | – | ~ |
629
- | **odg** | – | – | – | – | – | – | — | – | – | ~ |
630
- | **odf** | – | – | – | – | – | – | – | — | – | → |
631
- | **markdown** | ~ | – | ✗✗ | ~ | – | – | – | – | — | ~ |
632
- | **pdf** | ✗ | ✗ | | ✗ | ✗ | | ✗ | – | ✗✗ | — |
633
-
634
- 73 of 90 directional pairs are routable. The `ContentDocument`/`LayoutDocument` pivots are the hub, not PDF — fourteen bridges bypass PDF entirely.
626
+ | ↓ from \ to → | docx | pptx | xlsx | odt | odp | ods | odg | odf | markdown | csv | pdf |
627
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
628
+ | **docx** | — | ~ | – | ✓ | – | – | – | – | ✗ | ✗ | ~ |
629
+ | **pptx** | ~ | — | – | – | ✓ | – | – | – | – | ✗ | ~ |
630
+ | **xlsx** | – | – | — | – | – | ~ | – | – | ✗✗ | ~ | ~ |
631
+ | **odt** | ✓ | – | – | — | ~ | – | – | – | ✗ | ✗ | ~ |
632
+ | **odp** | – | ✓ | – | ~ | — | – | – | – | – | ✗ | ~ |
633
+ | **ods** | – | – | ~ | – | – | — | – | – | – | ~ | ~ |
634
+ | **odg** | – | – | – | – | – | – | — | – | – | ✗ | ~ |
635
+ | **odf** | – | – | – | – | – | – | – | — | – | – | → |
636
+ | **markdown** | ~ | – | ✗✗ | ~ | – | – | – | – | — | ✗✗ | ~ |
637
+ | **csv** | ✗ | ✗ | | ✗ | ✗ | | ✗ | – | ✗✗ | — | ~ |
638
+ | **pdf** | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | – | ✗✗ | ✗ | — |
639
+
640
+ 91 of 110 directional pairs are routable. The `ContentDocument`/`LayoutDocument` pivots are the hub, not PDF — eighteen bridges bypass PDF entirely.
635
641
 
636
642
  **X → PDF** is a genuine layout render: positioned text, images, tables, lists, vector primitives, styled through the full cascade. It is a faithful visual approximation, not pixel-identical — closeness depends on font availability.
637
643
 
@@ -643,9 +649,9 @@ Read as **row → column**. `✓` lossless, `~` bounded, `✗` lossy, `✗✗` s
643
649
 
644
650
  **PDF → ods** recovers what was printed, not what was entered. The printed string always survives in `displayText`; re-typed `value` is explicitly probabilistic inference.
645
651
 
646
- **`markdownToPdf`/`pdfToMarkdown`** is the lossiest round trip: `markdownToPdf` is faithful, but `pdfToMarkdown` stacks reconstruction lossiness PLUS markdown's coarser vocabulary (no colour, font, size, alignment).
652
+ **`markdownToPdf`/`pdfToMarkdown`** is the lossiest round trip: `markdownToPdf` is faithful, but `pdfToMarkdown` stacks reconstruction lossiness PLUS markdown's coarser vocabulary (no colour, font, size, alignment). The PDF-composed markdown bridges (`xlsxToMarkdown`/`markdownToXlsx`, `csvToMarkdown`/`markdownToCsv`) stack the same two losses in both directions — hence their `✗✗` cells.
647
653
 
648
- **The first three bridge pairs** (odt⇄docx, odp⇄pptx, ods⇄xlsx) bypass PDF entirely — no layout engine, no reconstruction. Text, styling, tables, lists, rotated shapes survive completely. `ods⇄xlsx` has small format-boundary limits (time cells, formula dialects). Embedded formulas survive `odtToDocx` as real OOXML math.
654
+ **The five same-variant bridge pairs** (odt⇄docx, odp⇄pptx, ods⇄xlsx, csv⇄ods, csv⇄xlsx) bypass PDF entirely — no layout engine, no reconstruction. Text, styling, tables, lists, rotated shapes survive completely. `ods⇄xlsx` has small format-boundary limits (time cells, formula dialects). Embedded formulas survive `odtToDocx` as real OOXML math. The csv pairs are bounded by what csv itself carries: toward ods/xlsx nothing the csv had is lost, while writing to csv collapses each cell to its `displayText` — formulas become their rendered values, formatting disappears, and a multi-sheet source must name the sheet it wants.
649
655
 
650
656
  **The two markdown bridge pairs** bypass PDF too, but markdown's grammar has no construct for colour/font/size/alignment — `docxToMarkdown`/`odtToMarkdown` drop them (format-boundary loss, not approximation).
651
657
 
@@ -15,6 +15,9 @@ const require_odf_odp_read = require("../odf/odp/read.cjs");
15
15
  const require_odf_ods_read = require("../odf/ods/read.cjs");
16
16
  const require_odf_odg_read = require("../odf/odg/read.cjs");
17
17
  const require_markdown_text = require("../markdown/text.cjs");
18
+ const require_csv_text = require("../csv/text.cjs");
19
+ const require_csv_read = require("../csv/read.cjs");
20
+ const require_csv_write = require("../csv/write.cjs");
18
21
  const require_ports_abort = require("../ports/abort.cjs");
19
22
  const require_package_codec = require("../package-codec.cjs");
20
23
  let ooxml_js = require("ooxml.js");
@@ -81,6 +84,10 @@ const DOCUMENT_FORMAT_CODECS = {
81
84
  }),
82
85
  write: (content) => require_markdown_text.encodeMarkdownText(require_markdown_write.buildMarkdownText(content))
83
86
  } },
87
+ csv: { content: {
88
+ read: (bytes) => require_csv_read.readCsvContent(require_csv_text.decodeCsvText(bytes)),
89
+ write: (content) => require_csv_text.encodeCsvText(require_csv_write.buildCsvText(content))
90
+ } },
84
91
  pdf: { layout: {
85
92
  read: (bytes, options) => (0, pdf_codec.readPdf)(requireArrayBufferBytes(bytes), { signal: options?.signal }),
86
93
  write: (layout, options) => (0, pdf_codec.writePdf)(layout, { signal: options?.signal })
@@ -14,6 +14,9 @@ import { readOdpContent } from "../odf/odp/read.js";
14
14
  import { readOdsContent } from "../odf/ods/read.js";
15
15
  import { readOdgContent } from "../odf/odg/read.js";
16
16
  import { decodeMarkdownText, encodeMarkdownText } from "../markdown/text.js";
17
+ import { decodeCsvText, encodeCsvText } from "../csv/text.js";
18
+ import { readCsvContent } from "../csv/read.js";
19
+ import { buildCsvText } from "../csv/write.js";
17
20
  import { throwIfAborted } from "../ports/abort.js";
18
21
  import { decodeDocumentPackage, encodeDocumentPackage } from "../package-codec.js";
19
22
  import { buildXlsxPackage, readXlsxContent } from "ooxml.js";
@@ -80,6 +83,10 @@ const DOCUMENT_FORMAT_CODECS = {
80
83
  }),
81
84
  write: (content) => encodeMarkdownText(buildMarkdownText(content))
82
85
  } },
86
+ csv: { content: {
87
+ read: (bytes) => readCsvContent(decodeCsvText(bytes)),
88
+ write: (content) => encodeCsvText(buildCsvText(content))
89
+ } },
83
90
  pdf: { layout: {
84
91
  read: (bytes, options) => readPdf(requireArrayBufferBytes(bytes), { signal: options?.signal }),
85
92
  write: (layout, options) => writePdf(layout, { signal: options?.signal })
@@ -31,6 +31,11 @@ const FORMAT_CAPABILITIES = {
31
31
  variant: "spreadsheet",
32
32
  hasLayoutPath: false
33
33
  },
34
+ csv: {
35
+ format: "csv",
36
+ variant: "spreadsheet",
37
+ hasLayoutPath: false
38
+ },
34
39
  odg: {
35
40
  format: "odg",
36
41
  variant: "drawing",
@@ -30,6 +30,11 @@ const FORMAT_CAPABILITIES = {
30
30
  variant: "spreadsheet",
31
31
  hasLayoutPath: false
32
32
  },
33
+ csv: {
34
+ format: "csv",
35
+ variant: "spreadsheet",
36
+ hasLayoutPath: false
37
+ },
33
38
  odg: {
34
39
  format: "odg",
35
40
  variant: "drawing",
@@ -59,7 +59,25 @@ const xlsxMarkdownCodec = zod.z.codec(require_model_bytes.XlsxBytesSchema, requi
59
59
  decode: (xlsxBytes) => require_convert_convert.xlsxToMarkdown(xlsxBytes),
60
60
  encode: (markdownBytes) => require_convert_convert.markdownToXlsx(markdownBytes)
61
61
  });
62
+ const csvPdfCodec = zod.z.codec(require_model_bytes.CsvBytesSchema, require_model_bytes.PdfBytesSchema, {
63
+ decode: (csvBytes) => require_convert_convert.csvToPdf(csvBytes),
64
+ encode: (pdfBytes) => require_convert_convert.pdfToCsv(pdfBytes)
65
+ });
66
+ const odsCsvCodec = zod.z.codec(require_model_bytes.OdsBytesSchema, require_model_bytes.CsvBytesSchema, {
67
+ decode: (odsBytes) => require_convert_convert.odsToCsv(odsBytes),
68
+ encode: (csvBytes) => require_convert_convert.csvToOds(csvBytes)
69
+ });
70
+ const xlsxCsvCodec = zod.z.codec(require_model_bytes.XlsxBytesSchema, require_model_bytes.CsvBytesSchema, {
71
+ decode: (xlsxBytes) => require_convert_convert.xlsxToCsv(xlsxBytes),
72
+ encode: (csvBytes) => require_convert_convert.csvToXlsx(csvBytes)
73
+ });
74
+ const csvMarkdownCodec = zod.z.codec(require_model_bytes.CsvBytesSchema, require_model_bytes.MarkdownBytesSchema, {
75
+ decode: (csvBytes) => require_convert_convert.csvToMarkdown(csvBytes),
76
+ encode: (markdownBytes) => require_convert_convert.markdownToCsv(markdownBytes)
77
+ });
62
78
  //#endregion
79
+ exports.csvMarkdownCodec = csvMarkdownCodec;
80
+ exports.csvPdfCodec = csvPdfCodec;
63
81
  exports.docxPdfCodec = docxPdfCodec;
64
82
  exports.markdownDocxCodec = markdownDocxCodec;
65
83
  exports.markdownOdtCodec = markdownOdtCodec;
@@ -67,10 +85,12 @@ exports.markdownPdfCodec = markdownPdfCodec;
67
85
  exports.odgPdfCodec = odgPdfCodec;
68
86
  exports.odpPdfCodec = odpPdfCodec;
69
87
  exports.odpPptxCodec = odpPptxCodec;
88
+ exports.odsCsvCodec = odsCsvCodec;
70
89
  exports.odsPdfCodec = odsPdfCodec;
71
90
  exports.odsXlsxCodec = odsXlsxCodec;
72
91
  exports.odtDocxCodec = odtDocxCodec;
73
92
  exports.odtPdfCodec = odtPdfCodec;
74
93
  exports.pptxPdfCodec = pptxPdfCodec;
94
+ exports.xlsxCsvCodec = xlsxCsvCodec;
75
95
  exports.xlsxMarkdownCodec = xlsxMarkdownCodec;
76
96
  exports.xlsxPdfCodec = xlsxPdfCodec;
@@ -14,5 +14,9 @@ declare const odsXlsxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint
14
14
  declare const markdownDocxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
15
15
  declare const markdownOdtCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
16
16
  declare const xlsxMarkdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
17
+ declare const csvPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
18
+ declare const odsCsvCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
19
+ declare const xlsxCsvCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
20
+ declare const csvMarkdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
17
21
  //#endregion
18
- export { docxPdfCodec, markdownDocxCodec, markdownOdtCodec, markdownPdfCodec, odgPdfCodec, odpPdfCodec, odpPptxCodec, odsPdfCodec, odsXlsxCodec, odtDocxCodec, odtPdfCodec, pptxPdfCodec, xlsxMarkdownCodec, xlsxPdfCodec };
22
+ export { csvMarkdownCodec, csvPdfCodec, docxPdfCodec, markdownDocxCodec, markdownOdtCodec, markdownPdfCodec, odgPdfCodec, odpPdfCodec, odpPptxCodec, odsCsvCodec, odsPdfCodec, odsXlsxCodec, odtDocxCodec, odtPdfCodec, pptxPdfCodec, xlsxCsvCodec, xlsxMarkdownCodec, xlsxPdfCodec };
@@ -14,5 +14,9 @@ declare const odsXlsxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint
14
14
  declare const markdownDocxCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
15
15
  declare const markdownOdtCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
16
16
  declare const xlsxMarkdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
17
+ declare const csvPdfCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
18
+ declare const odsCsvCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
19
+ declare const xlsxCsvCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
20
+ declare const csvMarkdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
17
21
  //#endregion
18
- export { docxPdfCodec, markdownDocxCodec, markdownOdtCodec, markdownPdfCodec, odgPdfCodec, odpPdfCodec, odpPptxCodec, odsPdfCodec, odsXlsxCodec, odtDocxCodec, odtPdfCodec, pptxPdfCodec, xlsxMarkdownCodec, xlsxPdfCodec };
22
+ export { csvMarkdownCodec, csvPdfCodec, docxPdfCodec, markdownDocxCodec, markdownOdtCodec, markdownPdfCodec, odgPdfCodec, odpPdfCodec, odpPptxCodec, odsCsvCodec, odsPdfCodec, odsXlsxCodec, odtDocxCodec, odtPdfCodec, pptxPdfCodec, xlsxCsvCodec, xlsxMarkdownCodec, xlsxPdfCodec };
@@ -1,5 +1,5 @@
1
- import { DocxBytesSchema, MarkdownBytesSchema, OdgBytesSchema, OdpBytesSchema, OdsBytesSchema, OdtBytesSchema, PdfBytesSchema, PptxBytesSchema, XlsxBytesSchema } from "../model/bytes.js";
2
- import { docxToMarkdown, docxToOdt, docxToPdf, markdownToDocx, markdownToOdt, markdownToPdf, markdownToXlsx, odgToPdf, odpToPdf, odpToPptx, odsToPdf, odsToXlsx, odtToDocx, odtToMarkdown, odtToPdf, pdfToDocx, pdfToMarkdown, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pdfToXlsx, pptxToOdp, pptxToPdf, xlsxToMarkdown, xlsxToOds, xlsxToPdf } from "./convert.js";
1
+ import { CsvBytesSchema, DocxBytesSchema, MarkdownBytesSchema, OdgBytesSchema, OdpBytesSchema, OdsBytesSchema, OdtBytesSchema, PdfBytesSchema, PptxBytesSchema, XlsxBytesSchema } from "../model/bytes.js";
2
+ import { csvToMarkdown, csvToOds, csvToPdf, csvToXlsx, docxToMarkdown, docxToOdt, docxToPdf, markdownToCsv, markdownToDocx, markdownToOdt, markdownToPdf, markdownToXlsx, odgToPdf, odpToPdf, odpToPptx, odsToCsv, odsToPdf, odsToXlsx, odtToDocx, odtToMarkdown, odtToPdf, pdfToCsv, pdfToDocx, pdfToMarkdown, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pdfToXlsx, pptxToOdp, pptxToPdf, xlsxToCsv, xlsxToMarkdown, xlsxToOds, xlsxToPdf } from "./convert.js";
3
3
  import { z } from "zod";
4
4
  //#region src/convert/codec.ts
5
5
  const docxPdfCodec = z.codec(DocxBytesSchema, PdfBytesSchema, {
@@ -58,5 +58,21 @@ const xlsxMarkdownCodec = z.codec(XlsxBytesSchema, MarkdownBytesSchema, {
58
58
  decode: (xlsxBytes) => xlsxToMarkdown(xlsxBytes),
59
59
  encode: (markdownBytes) => markdownToXlsx(markdownBytes)
60
60
  });
61
+ const csvPdfCodec = z.codec(CsvBytesSchema, PdfBytesSchema, {
62
+ decode: (csvBytes) => csvToPdf(csvBytes),
63
+ encode: (pdfBytes) => pdfToCsv(pdfBytes)
64
+ });
65
+ const odsCsvCodec = z.codec(OdsBytesSchema, CsvBytesSchema, {
66
+ decode: (odsBytes) => odsToCsv(odsBytes),
67
+ encode: (csvBytes) => csvToOds(csvBytes)
68
+ });
69
+ const xlsxCsvCodec = z.codec(XlsxBytesSchema, CsvBytesSchema, {
70
+ decode: (xlsxBytes) => xlsxToCsv(xlsxBytes),
71
+ encode: (csvBytes) => csvToXlsx(csvBytes)
72
+ });
73
+ const csvMarkdownCodec = z.codec(CsvBytesSchema, MarkdownBytesSchema, {
74
+ decode: (csvBytes) => csvToMarkdown(csvBytes),
75
+ encode: (markdownBytes) => markdownToCsv(markdownBytes)
76
+ });
61
77
  //#endregion
62
- export { docxPdfCodec, markdownDocxCodec, markdownOdtCodec, markdownPdfCodec, odgPdfCodec, odpPdfCodec, odpPptxCodec, odsPdfCodec, odsXlsxCodec, odtDocxCodec, odtPdfCodec, pptxPdfCodec, xlsxMarkdownCodec, xlsxPdfCodec };
78
+ export { csvMarkdownCodec, csvPdfCodec, docxPdfCodec, markdownDocxCodec, markdownOdtCodec, markdownPdfCodec, odgPdfCodec, odpPdfCodec, odpPptxCodec, odsCsvCodec, odsPdfCodec, odsXlsxCodec, odtDocxCodec, odtPdfCodec, pptxPdfCodec, xlsxCsvCodec, xlsxMarkdownCodec, xlsxPdfCodec };
@@ -16,6 +16,9 @@ const require_odf_odp_read = require("../odf/odp/read.cjs");
16
16
  const require_odf_ods_read = require("../odf/ods/read.cjs");
17
17
  const require_odf_odg_read = require("../odf/odg/read.cjs");
18
18
  const require_markdown_text = require("../markdown/text.cjs");
19
+ const require_csv_text = require("../csv/text.cjs");
20
+ const require_csv_read = require("../csv/read.cjs");
21
+ const require_csv_write = require("../csv/write.cjs");
19
22
  const require_layout_engine = require("../layout/engine.cjs");
20
23
  const require_layout_slides = require("../layout/slides.cjs");
21
24
  const require_ports_abort = require("../ports/abort.cjs");
@@ -39,8 +42,12 @@ const CONTENT_FORMATS = [
39
42
  "odp",
40
43
  "ods",
41
44
  "odg",
45
+ "csv",
42
46
  "markdown"
43
47
  ];
48
+ function isTextFormatNode(node) {
49
+ return !node.hasSourcePackage;
50
+ }
44
51
  const FORMAT_NODES = {
45
52
  docx: {
46
53
  variant: "wordprocessing",
@@ -116,6 +123,21 @@ const FORMAT_NODES = {
116
123
  build: (content) => require_markdown_write.buildMarkdownText(content),
117
124
  encode: (text) => require_markdown_text.encodeMarkdownText(text),
118
125
  hasSourcePackage: false
126
+ },
127
+ csv: {
128
+ variant: "spreadsheet",
129
+ family: "csv",
130
+ decode: (bytes) => require_csv_text.decodeCsvText(bytes),
131
+ read: (text, options) => require_csv_read.readCsvContent(text, {
132
+ delimiter: options?.delimiter,
133
+ onCellTypeInference: options?.onCellTypeInference
134
+ }),
135
+ build: (content, options) => require_csv_write.buildCsvText(content, {
136
+ delimiter: options?.delimiter,
137
+ sheet: options?.sheet
138
+ }),
139
+ encode: (text) => require_csv_text.encodeCsvText(text),
140
+ hasSourcePackage: false
119
141
  }
120
142
  };
121
143
  const LAYOUT_CAPABLE = /* @__PURE__ */ new Set([
@@ -162,7 +184,7 @@ function executeBridge(source, target, bytes, options) {
162
184
  const sourceNode = FORMAT_NODES[source];
163
185
  const targetNode = FORMAT_NODES[target];
164
186
  let content;
165
- if (sourceNode.family === "markdown") {
187
+ if (isTextFormatNode(sourceNode)) {
166
188
  const text = sourceNode.decode(bytes);
167
189
  content = sourceNode.read(text, options);
168
190
  } else {
@@ -182,8 +204,8 @@ function executeBridge(source, target, bytes, options) {
182
204
  formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
183
205
  content: buildContent
184
206
  });
185
- if (targetNode.family === "markdown") {
186
- const text = targetNode.build(buildContent);
207
+ if (isTextFormatNode(targetNode)) {
208
+ const text = targetNode.build(buildContent, options);
187
209
  return targetNode.encode(text);
188
210
  }
189
211
  const pkg = targetNode.build(buildContent, options);
@@ -194,7 +216,7 @@ function executeToPdf(format, bytes, options) {
194
216
  const node = FORMAT_NODES[format];
195
217
  let content;
196
218
  let fonts;
197
- if (node.family === "markdown") {
219
+ if (isTextFormatNode(node)) {
198
220
  require_ports_abort.throwIfAborted(options?.signal);
199
221
  const text = node.decode(bytes);
200
222
  const read = node.read(text, options);
@@ -295,7 +317,10 @@ function executeFromPdf(target, bytes, options) {
295
317
  signal: options?.signal,
296
318
  sink: options?.sink
297
319
  });
298
- const content = RECONSTRUCTORS[node.variant](layout, { signal: options?.signal });
320
+ const content = RECONSTRUCTORS[node.variant](layout, {
321
+ signal: options?.signal,
322
+ onCellTypeInference: options?.onCellTypeInference
323
+ });
299
324
  const pages = layout.pages.map((page) => ({
300
325
  widthPt: page.widthPt,
301
326
  heightPt: page.heightPt
@@ -305,8 +330,8 @@ function executeFromPdf(target, bytes, options) {
305
330
  content,
306
331
  pages
307
332
  });
308
- if (node.family === "markdown") {
309
- const text = node.build(content);
333
+ if (isTextFormatNode(node)) {
334
+ const text = node.build(content, options);
310
335
  return node.encode(text);
311
336
  }
312
337
  const pkg = node.build(content);
@@ -1,6 +1,7 @@
1
1
  import { t as ClockPort } from "../clock-C7SUuYN0.cjs";
2
2
  import { DocumentFormat } from "./port.cjs";
3
3
  import { t as ContentVariant } from "../capability-an5gSNsu.cjs";
4
+ import { CellTypeInferenceSink } from "../layout/cell-typing.cjs";
4
5
  import { t as OmmlDiagnostic } from "../shared-DLZ3IQUl.cjs";
5
6
  import { ContentDocument, DocumentPackage, FontSubstitution, ProvidedFont } from "document-schema.js";
6
7
  import { MarkdownImageResolver } from "markdown-codec";
@@ -21,9 +22,12 @@ interface UnifiedConversionOptions {
21
22
  readonly sourcePath?: string;
22
23
  }) => void;
23
24
  readonly images?: MarkdownImageResolver;
25
+ readonly delimiter?: string;
26
+ readonly sheet?: string;
27
+ readonly onCellTypeInference?: CellTypeInferenceSink;
24
28
  readonly clock?: ClockPort;
25
29
  }
26
- type ContentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'markdown';
30
+ type ContentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'csv' | 'markdown';
27
31
  type LayoutVariant = Exclude<ContentVariant, 'formula'>;
28
32
  interface PackageFormatNode {
29
33
  readonly variant: LayoutVariant;
@@ -34,16 +38,16 @@ interface PackageFormatNode {
34
38
  readonly encode: (pkg: SourcePackage) => Uint8Array<ArrayBuffer>;
35
39
  readonly hasSourcePackage: true;
36
40
  }
37
- interface MarkdownFormatNode {
41
+ interface TextFormatNode {
38
42
  readonly variant: LayoutVariant;
39
- readonly family: 'markdown';
43
+ readonly family: 'markdown' | 'csv';
40
44
  readonly decode: (bytes: Uint8Array<ArrayBuffer>) => string;
41
45
  readonly read: (text: string, options?: UnifiedConversionOptions) => ContentDocument;
42
- readonly build: (content: ContentDocument) => string;
46
+ readonly build: (content: ContentDocument, options?: UnifiedConversionOptions) => string;
43
47
  readonly encode: (text: string) => Uint8Array<ArrayBuffer>;
44
48
  readonly hasSourcePackage: false;
45
49
  }
46
- type FormatNode = PackageFormatNode | MarkdownFormatNode;
50
+ type FormatNode = PackageFormatNode | TextFormatNode;
47
51
  declare const FORMAT_NODES: Readonly<Record<ContentFormat, FormatNode>>;
48
52
  type HopExecutor = 'bridge' | 'toPdf' | 'fromPdf';
49
53
  interface CompositionHop {
@@ -1,6 +1,7 @@
1
1
  import { t as ClockPort } from "../clock-C7SUuYN0.js";
2
2
  import { DocumentFormat } from "./port.js";
3
3
  import { t as ContentVariant } from "../capability-DX0lCSiI.js";
4
+ import { CellTypeInferenceSink } from "../layout/cell-typing.js";
4
5
  import { t as OmmlDiagnostic } from "../shared-DUOzjwcL.js";
5
6
  import { Package } from "ooxml.js";
6
7
  import { ContentDocument, DocumentPackage, FontSubstitution, ProvidedFont } from "document-schema.js";
@@ -21,9 +22,12 @@ interface UnifiedConversionOptions {
21
22
  readonly sourcePath?: string;
22
23
  }) => void;
23
24
  readonly images?: MarkdownImageResolver;
25
+ readonly delimiter?: string;
26
+ readonly sheet?: string;
27
+ readonly onCellTypeInference?: CellTypeInferenceSink;
24
28
  readonly clock?: ClockPort;
25
29
  }
26
- type ContentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'markdown';
30
+ type ContentFormat = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'odp' | 'ods' | 'odg' | 'csv' | 'markdown';
27
31
  type LayoutVariant = Exclude<ContentVariant, 'formula'>;
28
32
  interface PackageFormatNode {
29
33
  readonly variant: LayoutVariant;
@@ -34,16 +38,16 @@ interface PackageFormatNode {
34
38
  readonly encode: (pkg: SourcePackage) => Uint8Array<ArrayBuffer>;
35
39
  readonly hasSourcePackage: true;
36
40
  }
37
- interface MarkdownFormatNode {
41
+ interface TextFormatNode {
38
42
  readonly variant: LayoutVariant;
39
- readonly family: 'markdown';
43
+ readonly family: 'markdown' | 'csv';
40
44
  readonly decode: (bytes: Uint8Array<ArrayBuffer>) => string;
41
45
  readonly read: (text: string, options?: UnifiedConversionOptions) => ContentDocument;
42
- readonly build: (content: ContentDocument) => string;
46
+ readonly build: (content: ContentDocument, options?: UnifiedConversionOptions) => string;
43
47
  readonly encode: (text: string) => Uint8Array<ArrayBuffer>;
44
48
  readonly hasSourcePackage: false;
45
49
  }
46
- type FormatNode = PackageFormatNode | MarkdownFormatNode;
50
+ type FormatNode = PackageFormatNode | TextFormatNode;
47
51
  declare const FORMAT_NODES: Readonly<Record<ContentFormat, FormatNode>>;
48
52
  type HopExecutor = 'bridge' | 'toPdf' | 'fromPdf';
49
53
  interface CompositionHop {