document-cli 5.1.4 → 5.1.5

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
@@ -168,7 +168,7 @@ document-cli set-metadata report.docx report.docx --set-title "Q3 Report" --set-
168
168
  document-cli set-metadata report.docx report.odt --set-keywords "draft,internal"
169
169
  ```
170
170
 
171
- **`outline <input>`** — prints a document's outline: the table-of-contents projection over the tree-form `DocumentTree` a conversion of that document builds — headings nested by heading level, list items nested under their heading or slide, one group per slide (labelled `Slide N`), sheet (labelled with the sheet's own name), or draw page (labelled `Page N`) — rendered as indented text, two spaces per nesting depth. Leaves render their own text (a paragraph's runs, a table's cell text, an image's alt text, a formula's LaTeX) or their kind in brackets when they carry none (`[page-break]`, `[vector]`, `[embeddedObject]`). Works on any of the twelve readable formats: the command runs the cheapest conversion that still leaves a package behind a PDF-bypassing bridge to a sibling format, so no layout engine runs (`docx`→`odt`, `markdown`→`docx`, `ods`→`xlsx`, ...); `pdf` reconstructs through `pdf-to-docx` and `odf` renders through `odf-to-pdf`, the one conversion each of those formats has — and projects that package's tree through [`document-outline.js`](../document-outline.js/README.md)'s own `buildOutline`, this command being that package's first real consumer. `--json` emits the outline tree itself — groups as `{ text, level, children }`, leaves as the package leaves they are — rather than a CLI-private shape; the internal conversion's diagnostics (a pdf reconstruction's parse warnings, say) reach stderr exactly as they would on the matching conversion command. `--from <format>` names the source format when the input path carries no recognised extension to infer it from — the only way to outline a document read from stdin (`-`), which otherwise has no extension to read at all. Heading nesting depends on the source document actually carrying a heading-level signal on disk (`w:outlineLvl` for docx, `text:outline-level` for odt) — present in anything authored by Word or LibreOffice, and always present for a markdown source, whose own reader parses `#`/`##` headings directly; a docx or odt this ecosystem's own writers produce does not currently stamp that signal even though the paragraph still carries its `Heading1`/`Heading2`-style reference, so outlining a docx/odt generated by this CLI's own conversions loses heading nesting specifically (list nesting and slide/sheet/page grouping are unaffected):
171
+ **`outline <input>`** — prints a document's outline: the table-of-contents projection over the tree-form `DocumentTree` read straight off the source document's own bytes — headings nested by heading level, list items nested under their heading or slide, one group per slide (labelled `Slide N`), sheet (labelled with the sheet's own name), or draw page (labelled `Page N`) — rendered as indented text, two spaces per nesting depth. Leaves render their own text (a paragraph's runs, a table's cell text, an image's alt text, a formula's LaTeX) or their kind in brackets when they carry none (`[page-break]`, `[vector]`, `[embeddedObject]`). Works on any of the twelve readable formats: the command reads the source's own native tree directly (documents.js's `readNativeDocumentTree`) — no bridging conversion runs and no output bytes are discarded — and projects that tree through [`document-outline.js`](../document-outline.js/README.md)'s own `buildOutline`, this command being that package's first real consumer. `--json` emits the outline tree itself — groups as `{ text, level, children }`, leaves as the package leaves they are — rather than a CLI-private shape; a `pdf` source's own `readPdf` parse diagnostics still reach stderr exactly as they would on the matching `pdf-to-docx` command. `--from <format>` names the source format when the input path carries no recognised extension to infer it from — the only way to outline a document read from stdin (`-`), which otherwise has no extension to read at all. Heading nesting depends on the source document actually carrying a heading-level signal on disk (`w:outlineLvl` for docx, `text:outline-level` for odt) — present in anything authored by Word or LibreOffice, and always present for a markdown source, whose own reader parses `#`/`##` headings directly; a docx or odt this ecosystem's own writers produce does not currently stamp that signal even though the paragraph still carries its `Heading1`/`Heading2`-style reference, so outlining a docx/odt generated by this CLI's own conversions loses heading nesting specifically (list nesting and slide/sheet/page grouping are unaffected):
172
172
 
173
173
  ```sh
174
174
  document-cli outline report.docx
@@ -191,7 +191,7 @@ The explicit conversions, `convert`, `odm-to-pdf`, `odb-to-xlsx`, `odb-to-csv`,
191
191
 
192
192
  Three further flags select what a csv or svg edge of a conversion works on, threaded straight into documents.js's own `ConversionOptions`: `--delimiter <char>` (the field delimiter a csv source reads with, or a csv target writes with — default `,`), `--sheet <name>` (the sheet a csv target writes, required when the source document has more than one), and `--page <index>` (the 0-based page an svg target draws, required when the source document has more than one). On the explicit commands they are registered only where the pair can reach the edge in question — `--delimiter` on any pair with a csv edge, `--sheet` on a csv target, `--page` on an svg target — and unconditionally on `convert` and `from-package`, whose target is only known once the output path or `--to` resolves at run time (the same registration reasoning the font flags below document). Leaving `--sheet` or `--page` unanswered on an ambiguous document fails with exit `3`, naming the sheets or page count to pick from:
193
193
 
194
- `--dump-package <file>` is one flag further, registered only on the explicit conversions and `convert` — it writes the intermediate `DocumentTree` (the tree form: content grouped one group per container, the content nodes carrying their own rendered `frames`, plus the `pages` geometry those frames index into and the minted `styles` table at the root) that conversion built to a JSON file, tagged with its own version-pinned `$schema` — the URI _is_ the package's version — so `from-package` (above) can read it back in. Every conversion populates one, `odf-to-pdf` included its dump carries a `formula`-kind content and the one A4 page it renders (the formula's glyphs travel through the PDF writer's own positioned-formula channel rather than as frame-stamped page content); every PDF-bypassing bridge (`ods-to-xlsx`, `docx-to-pptx`, `odg-to-svg`, and every other content-format pair above) populates one too, just with `pages` always absent, since a bridge never runs a layout engine. `odm-to-pdf`/`odb-*`/`set-metadata` don't expose the flag at all, since none of them goes through `DocumentConverter.convert` in the first place. `odb-tables`, `odb-forms`, `odb-reports`, `fonts`, `docx-extras`, `metadata`, `formats`, and `pdf-inspect` each take only their own `--json` (plus `pdf-inspect`'s own `--full`); `odb-query` takes `--sql <text>`/`--query <savedName>` (mutually exclusive) alongside its own `--json`, with none of the shared flags above since it only reads and writes nothing; `from-package` and `set-metadata` each take `--to <format>` alongside the shared flags in this table; `outline` takes the shared flags except `--out` (it prints to stdout and writes no file), plus its own `--from <format>` for a source format extension inference can't resolve — it runs a conversion internally to obtain the package it projects, so its diagnostics and `--timeout` behave like any conversion's; `odb-render-report` takes `--report <name>` and `--to <format>` alongside the shared flags and the font flags below; `tui` takes no flags at all, only an optional positional file.
194
+ `--dump-package <file>` is one flag further, registered only on the explicit conversions and `convert` — it writes the SOURCE document's own native `DocumentTree` (documents.js's `readNativeDocumentTree`, read straight off the input bytes a second time, independent of `--to`/the output path) to a JSON file, tagged with its own version-pinned `$schema` — the URI _is_ the package's version — so `from-package` (above) can read it back in. This is deliberately not the same tree `--to`'s own conversion produces internally: a target sharing no `ContentDocument` variant with the source composes through a lossy cross-variant bridge or a pdf pivot to get there (`xlsx-to-markdown`, say), and reporting that intermediate hop's shape would mean an xlsx source's own dump carries a wordprocessing tree with no sheet/cell/formula/A1 data at all rather than the workbook it actually is ([ExaDev/documents.js#823](https://github.com/ExaDev/documents.js/issues/823)) `--dump-package` is about what the source carries, not about how `--to` got there. Every source format populates one: a `pdf` source's dump carries `pages` and per-node `frames` (a PDF has no representation other than positioned layout — the identical reconstruction `pdf-to-docx` runs), and every other source's dump is content-only, with no `pages` and no `frames` at all, `odf` included (its dump carries a `formula`-kind content with no invented page geometry — a standalone formula document has no page concept of its own until something renders it). `odm-to-pdf`/`odb-*`/`set-metadata` don't expose the flag at all, since none of them goes through `DocumentConverter.convert` in the first place. `odb-tables`, `odb-forms`, `odb-reports`, `fonts`, `docx-extras`, `metadata`, `formats`, and `pdf-inspect` each take only their own `--json` (plus `pdf-inspect`'s own `--full`); `odb-query` takes `--sql <text>`/`--query <savedName>` (mutually exclusive) alongside its own `--json`, with none of the shared flags above since it only reads and writes nothing; `from-package` and `set-metadata` each take `--to <format>` alongside the shared flags in this table; `outline` takes the shared flags except `--out` (it prints to stdout and writes no file), plus its own `--from <format>` for a source format extension inference can't resolve — it reads the source's own native tree directly (the same `readNativeDocumentTree` primitive `--dump-package` uses), so its diagnostics and `--timeout` behave like any conversion's; `odb-render-report` takes `--report <name>` and `--to <format>` alongside the shared flags and the font flags below; `tui` takes no flags at all, only an optional positional file.
195
195
 
196
196
  ### Real fonts
197
197
 
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@ import { a as odbFormSummary, c as formatDocxExtrasLines, d as writeOutput, f as
3
3
  import { Command, CommanderError, InvalidArgumentError } from "commander";
4
4
  import { writeFile } from "node:fs/promises";
5
5
  import { basename, dirname, extname, join, resolve } from "node:path";
6
- import { CsvSheetNotFoundError, CsvSheetNotSpecifiedError, HsqldbSqlEvaluationError, HsqldbSqlParseError, HsqldbSqlUnsupportedError, OdbNoEmbeddedDataSourceError, OdbReportNotSpecifiedError, OdbTableNotFoundError, OdbTableNotSpecifiedError, OdbUnsupportedFormatError, OdmUnresolvedSectionError, PdfEncryptedError, PdfParseError, SvgMultiPageNotSpecifiedError, SvgPageNotFoundError, UnrecognizedDocumentSchemaError, UnsupportedFontSourceFormatError, buildCsvText, buildDocumentBytes, buildSvgText, createLocalDocumentConverter, decodeOdbPackage, decodePackage, documentFromJson, documentTreeWithSchema, encodeCsvText, encodeSvgText, evaluateSelect, extractSourceFontsForFormat, hsqldbCellDisplayText, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
6
+ import { CsvSheetNotFoundError, CsvSheetNotSpecifiedError, HsqldbSqlEvaluationError, HsqldbSqlParseError, HsqldbSqlUnsupportedError, OdbNoEmbeddedDataSourceError, OdbReportNotSpecifiedError, OdbTableNotFoundError, OdbTableNotSpecifiedError, OdbUnsupportedFormatError, OdmUnresolvedSectionError, PdfEncryptedError, PdfParseError, SvgMultiPageNotSpecifiedError, SvgPageNotFoundError, UnrecognizedDocumentSchemaError, UnsupportedFontSourceFormatError, buildCsvText, buildDocumentBytes, buildSvgText, createLocalDocumentConverter, decodeOdbPackage, decodePackage, documentFromJson, documentTreeWithSchema, encodeCsvText, encodeSvgText, evaluateSelect, extractSourceFontsForFormat, hsqldbCellDisplayText, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readNativeDocumentTree, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
7
7
  import { existsSync, readFileSync } from "node:fs";
8
8
  import { flattenTree } from "document-schema.js";
9
9
  import { buildOutline, isOutlineNode, outlineLeafText } from "document-outline.js";
@@ -168,6 +168,7 @@ function buildConversionAction(source, target) {
168
168
  try {
169
169
  const inputBytes = await readInput(input, { signal });
170
170
  const fonts = await loadProvidedFonts(options.fontFiles ?? [], { signal });
171
+ const images = createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input)));
171
172
  const result = await createLocalDocumentConverter().convert({
172
173
  source: {
173
174
  format: source,
@@ -182,7 +183,7 @@ function buildConversionAction(source, target) {
182
183
  quiet: options.quiet,
183
184
  command
184
185
  }) : void 0,
185
- images: createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input))),
186
+ images,
186
187
  delimiter: options.delimiter,
187
188
  sheet: options.sheet,
188
189
  page: options.page
@@ -195,8 +196,11 @@ function buildConversionAction(source, target) {
195
196
  });
196
197
  for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
197
198
  if (options.dumpPackage !== void 0) {
198
- if (result.package === void 0) process.stderr.write(`[${command}] this conversion does not produce an intermediate DocumentTree\n`);
199
- else await writeFile(options.dumpPackage, JSON.stringify(documentTreeWithSchema(result.package), void 0, 2));
199
+ const nativeTree = readNativeDocumentTree(source, new Uint8Array(inputBytes), {
200
+ signal,
201
+ images
202
+ });
203
+ await writeFile(options.dumpPackage, JSON.stringify(documentTreeWithSchema(nativeTree), void 0, 2));
200
204
  }
201
205
  reporter.summarize({
202
206
  output: resolvedOutput,
@@ -972,20 +976,6 @@ function registerOdmCommand(program) {
972
976
  }
973
977
  //#endregion
974
978
  //#region src/commands/outline.ts
975
- const OUTLINE_CONVERSION_TARGET = {
976
- docx: "odt",
977
- odt: "docx",
978
- markdown: "docx",
979
- pptx: "odp",
980
- odp: "pptx",
981
- xlsx: "ods",
982
- ods: "xlsx",
983
- csv: "xlsx",
984
- odg: "odp",
985
- svg: "odg",
986
- pdf: "docx",
987
- odf: "pdf"
988
- };
989
979
  const INDENT = " ";
990
980
  function singleLineText(text) {
991
981
  return text.replaceAll(/\s+/g, " ").trim();
@@ -1021,7 +1011,6 @@ async function runOutline(input, options) {
1021
1011
  process.stderr.write(`[${command}] ${source.errorMessage}\n`);
1022
1012
  return 2;
1023
1013
  }
1024
- const target = OUTLINE_CONVERSION_TARGET[source.format];
1025
1014
  const { signal, getAbortReason } = createRuntimeSignal({ timeoutMs: options.timeout });
1026
1015
  const reporter = createDiagnosticReporter({
1027
1016
  json: options.json,
@@ -1030,19 +1019,14 @@ async function runOutline(input, options) {
1030
1019
  });
1031
1020
  try {
1032
1021
  const inputBytes = await readInput(input, { signal });
1033
- const result = await createLocalDocumentConverter().convert({
1034
- source: {
1035
- format: source.format,
1036
- bytes: new Uint8Array(inputBytes)
1037
- },
1038
- targetFormat: target
1039
- }, {
1022
+ const tree = readNativeDocumentTree(source.format, new Uint8Array(inputBytes), {
1040
1023
  signal,
1041
- images: createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input)))
1024
+ images: createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input))),
1025
+ sink: (diagnostic) => {
1026
+ reporter.report(diagnostic);
1027
+ }
1042
1028
  });
1043
- for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
1044
- if (result.package === void 0) throw new Error(`the ${source.format}-to-${target} conversion produced no intermediate DocumentTree`);
1045
- const outline = buildOutline(result.package);
1029
+ const outline = buildOutline(tree);
1046
1030
  if (options.json) {
1047
1031
  process.stdout.write(`${JSON.stringify(outline, void 0, 2)}\n`);
1048
1032
  return 0;
@@ -1215,7 +1199,7 @@ function registerSetMetadataCommand(program) {
1215
1199
  }
1216
1200
  //#endregion
1217
1201
  //#region package.json
1218
- var version = "5.1.4";
1202
+ var version = "5.1.5";
1219
1203
  //#endregion
1220
1204
  //#region src/program.ts
1221
1205
  function createProgram() {
package/dist/index.cjs CHANGED
@@ -286,6 +286,7 @@ function buildConversionAction(source, target) {
286
286
  try {
287
287
  const inputBytes = await readInput(input, { signal });
288
288
  const fonts = await loadProvidedFonts(options.fontFiles ?? [], { signal });
289
+ const images = createFilesystemMarkdownImageResolver(input === "-" ? "." : (0, node_path.dirname)((0, node_path.resolve)(input)));
289
290
  const result = await (0, documents_js.createLocalDocumentConverter)().convert({
290
291
  source: {
291
292
  format: source,
@@ -300,7 +301,7 @@ function buildConversionAction(source, target) {
300
301
  quiet: options.quiet,
301
302
  command
302
303
  }) : void 0,
303
- images: createFilesystemMarkdownImageResolver(input === "-" ? "." : (0, node_path.dirname)((0, node_path.resolve)(input))),
304
+ images,
304
305
  delimiter: options.delimiter,
305
306
  sheet: options.sheet,
306
307
  page: options.page
@@ -313,8 +314,11 @@ function buildConversionAction(source, target) {
313
314
  });
314
315
  for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
315
316
  if (options.dumpPackage !== void 0) {
316
- if (result.package === void 0) process.stderr.write(`[${command}] this conversion does not produce an intermediate DocumentTree\n`);
317
- else await (0, node_fs_promises.writeFile)(options.dumpPackage, JSON.stringify((0, documents_js.documentTreeWithSchema)(result.package), void 0, 2));
317
+ const nativeTree = (0, documents_js.readNativeDocumentTree)(source, new Uint8Array(inputBytes), {
318
+ signal,
319
+ images
320
+ });
321
+ await (0, node_fs_promises.writeFile)(options.dumpPackage, JSON.stringify((0, documents_js.documentTreeWithSchema)(nativeTree), void 0, 2));
318
322
  }
319
323
  reporter.summarize({
320
324
  output: resolvedOutput,
@@ -1310,20 +1314,6 @@ function registerOdmCommand(program) {
1310
1314
  }
1311
1315
  //#endregion
1312
1316
  //#region src/commands/outline.ts
1313
- const OUTLINE_CONVERSION_TARGET = {
1314
- docx: "odt",
1315
- odt: "docx",
1316
- markdown: "docx",
1317
- pptx: "odp",
1318
- odp: "pptx",
1319
- xlsx: "ods",
1320
- ods: "xlsx",
1321
- csv: "xlsx",
1322
- odg: "odp",
1323
- svg: "odg",
1324
- pdf: "docx",
1325
- odf: "pdf"
1326
- };
1327
1317
  const INDENT = " ";
1328
1318
  function singleLineText(text) {
1329
1319
  return text.replaceAll(/\s+/g, " ").trim();
@@ -1359,7 +1349,6 @@ async function runOutline(input, options) {
1359
1349
  process.stderr.write(`[${command}] ${source.errorMessage}\n`);
1360
1350
  return 2;
1361
1351
  }
1362
- const target = OUTLINE_CONVERSION_TARGET[source.format];
1363
1352
  const { signal, getAbortReason } = createRuntimeSignal({ timeoutMs: options.timeout });
1364
1353
  const reporter = createDiagnosticReporter({
1365
1354
  json: options.json,
@@ -1368,19 +1357,14 @@ async function runOutline(input, options) {
1368
1357
  });
1369
1358
  try {
1370
1359
  const inputBytes = await readInput(input, { signal });
1371
- const result = await (0, documents_js.createLocalDocumentConverter)().convert({
1372
- source: {
1373
- format: source.format,
1374
- bytes: new Uint8Array(inputBytes)
1375
- },
1376
- targetFormat: target
1377
- }, {
1360
+ const tree = (0, documents_js.readNativeDocumentTree)(source.format, new Uint8Array(inputBytes), {
1378
1361
  signal,
1379
- images: createFilesystemMarkdownImageResolver(input === "-" ? "." : (0, node_path.dirname)((0, node_path.resolve)(input)))
1362
+ images: createFilesystemMarkdownImageResolver(input === "-" ? "." : (0, node_path.dirname)((0, node_path.resolve)(input))),
1363
+ sink: (diagnostic) => {
1364
+ reporter.report(diagnostic);
1365
+ }
1380
1366
  });
1381
- for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
1382
- if (result.package === void 0) throw new Error(`the ${source.format}-to-${target} conversion produced no intermediate DocumentTree`);
1383
- const outline = (0, document_outline_js.buildOutline)(result.package);
1367
+ const outline = (0, document_outline_js.buildOutline)(tree);
1384
1368
  if (options.json) {
1385
1369
  process.stdout.write(`${JSON.stringify(outline, void 0, 2)}\n`);
1386
1370
  return 0;
@@ -1553,7 +1537,7 @@ function registerSetMetadataCommand(program) {
1553
1537
  }
1554
1538
  //#endregion
1555
1539
  //#region package.json
1556
- var version = "5.1.4";
1540
+ var version = "5.1.5";
1557
1541
  //#endregion
1558
1542
  //#region src/program.ts
1559
1543
  function createProgram() {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { readFile, writeFile } from "node:fs/promises";
2
2
  import { basename, dirname, extname, join, resolve } from "node:path";
3
- import { CsvSheetNotFoundError, CsvSheetNotSpecifiedError, HsqldbSqlEvaluationError, HsqldbSqlParseError, HsqldbSqlUnsupportedError, OdbNoEmbeddedDataSourceError, OdbReportNotSpecifiedError, OdbTableNotFoundError, OdbTableNotSpecifiedError, OdbUnsupportedFormatError, OdmUnresolvedSectionError, PdfEncryptedError, PdfParseError, SvgMultiPageNotSpecifiedError, SvgPageNotFoundError, UnrecognizedDocumentSchemaError, UnsupportedFontSourceFormatError, buildCsvText, buildDocumentBytes, buildSvgText, createLocalDocumentConverter, decodeOdbPackage, decodePackage, describeFontFace, documentFromJson, documentTreeWithSchema, encodeCsvText, encodeSvgText, evaluateSelect, extractSourceFontsForFormat, hsqldbCellDisplayText, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
3
+ import { CsvSheetNotFoundError, CsvSheetNotSpecifiedError, HsqldbSqlEvaluationError, HsqldbSqlParseError, HsqldbSqlUnsupportedError, OdbNoEmbeddedDataSourceError, OdbReportNotSpecifiedError, OdbTableNotFoundError, OdbTableNotSpecifiedError, OdbUnsupportedFormatError, OdmUnresolvedSectionError, PdfEncryptedError, PdfParseError, SvgMultiPageNotSpecifiedError, SvgPageNotFoundError, UnrecognizedDocumentSchemaError, UnsupportedFontSourceFormatError, buildCsvText, buildDocumentBytes, buildSvgText, createLocalDocumentConverter, decodeOdbPackage, decodePackage, describeFontFace, documentFromJson, documentTreeWithSchema, encodeCsvText, encodeSvgText, evaluateSelect, extractSourceFontsForFormat, hsqldbCellDisplayText, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readNativeDocumentTree, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import { Command, InvalidArgumentError } from "commander";
6
6
  import { flattenTree } from "document-schema.js";
@@ -285,6 +285,7 @@ function buildConversionAction(source, target) {
285
285
  try {
286
286
  const inputBytes = await readInput(input, { signal });
287
287
  const fonts = await loadProvidedFonts(options.fontFiles ?? [], { signal });
288
+ const images = createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input)));
288
289
  const result = await createLocalDocumentConverter().convert({
289
290
  source: {
290
291
  format: source,
@@ -299,7 +300,7 @@ function buildConversionAction(source, target) {
299
300
  quiet: options.quiet,
300
301
  command
301
302
  }) : void 0,
302
- images: createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input))),
303
+ images,
303
304
  delimiter: options.delimiter,
304
305
  sheet: options.sheet,
305
306
  page: options.page
@@ -312,8 +313,11 @@ function buildConversionAction(source, target) {
312
313
  });
313
314
  for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
314
315
  if (options.dumpPackage !== void 0) {
315
- if (result.package === void 0) process.stderr.write(`[${command}] this conversion does not produce an intermediate DocumentTree\n`);
316
- else await writeFile(options.dumpPackage, JSON.stringify(documentTreeWithSchema(result.package), void 0, 2));
316
+ const nativeTree = readNativeDocumentTree(source, new Uint8Array(inputBytes), {
317
+ signal,
318
+ images
319
+ });
320
+ await writeFile(options.dumpPackage, JSON.stringify(documentTreeWithSchema(nativeTree), void 0, 2));
317
321
  }
318
322
  reporter.summarize({
319
323
  output: resolvedOutput,
@@ -1309,20 +1313,6 @@ function registerOdmCommand(program) {
1309
1313
  }
1310
1314
  //#endregion
1311
1315
  //#region src/commands/outline.ts
1312
- const OUTLINE_CONVERSION_TARGET = {
1313
- docx: "odt",
1314
- odt: "docx",
1315
- markdown: "docx",
1316
- pptx: "odp",
1317
- odp: "pptx",
1318
- xlsx: "ods",
1319
- ods: "xlsx",
1320
- csv: "xlsx",
1321
- odg: "odp",
1322
- svg: "odg",
1323
- pdf: "docx",
1324
- odf: "pdf"
1325
- };
1326
1316
  const INDENT = " ";
1327
1317
  function singleLineText(text) {
1328
1318
  return text.replaceAll(/\s+/g, " ").trim();
@@ -1358,7 +1348,6 @@ async function runOutline(input, options) {
1358
1348
  process.stderr.write(`[${command}] ${source.errorMessage}\n`);
1359
1349
  return 2;
1360
1350
  }
1361
- const target = OUTLINE_CONVERSION_TARGET[source.format];
1362
1351
  const { signal, getAbortReason } = createRuntimeSignal({ timeoutMs: options.timeout });
1363
1352
  const reporter = createDiagnosticReporter({
1364
1353
  json: options.json,
@@ -1367,19 +1356,14 @@ async function runOutline(input, options) {
1367
1356
  });
1368
1357
  try {
1369
1358
  const inputBytes = await readInput(input, { signal });
1370
- const result = await createLocalDocumentConverter().convert({
1371
- source: {
1372
- format: source.format,
1373
- bytes: new Uint8Array(inputBytes)
1374
- },
1375
- targetFormat: target
1376
- }, {
1359
+ const tree = readNativeDocumentTree(source.format, new Uint8Array(inputBytes), {
1377
1360
  signal,
1378
- images: createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input)))
1361
+ images: createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input))),
1362
+ sink: (diagnostic) => {
1363
+ reporter.report(diagnostic);
1364
+ }
1379
1365
  });
1380
- for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
1381
- if (result.package === void 0) throw new Error(`the ${source.format}-to-${target} conversion produced no intermediate DocumentTree`);
1382
- const outline = buildOutline(result.package);
1366
+ const outline = buildOutline(tree);
1383
1367
  if (options.json) {
1384
1368
  process.stdout.write(`${JSON.stringify(outline, void 0, 2)}\n`);
1385
1369
  return 0;
@@ -1552,7 +1536,7 @@ function registerSetMetadataCommand(program) {
1552
1536
  }
1553
1537
  //#endregion
1554
1538
  //#region package.json
1555
- var version = "5.1.4";
1539
+ var version = "5.1.5";
1556
1540
  //#endregion
1557
1541
  //#region src/program.ts
1558
1542
  function createProgram() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-cli",
3
- "version": "5.1.4",
3
+ "version": "5.1.5",
4
4
  "description": "CLI and interactive Ink TUI for documents.js: every docx/pptx/odt/odp/ods/odg/odf/pdf/odm/odb/xlsx/csv/svg/markdown conversion, bridge, and editor as a scriptable command or a terminal app.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -90,9 +90,9 @@
90
90
  "packageManager": "pnpm@11.6.0",
91
91
  "dependencies": {
92
92
  "commander": "^15.0.0",
93
- "document-outline.js": "^3.1.1",
94
- "document-schema.js": "^5.2.0",
95
- "documents.js": "^6.1.4",
93
+ "document-outline.js": "^3.2.0",
94
+ "document-schema.js": "^5.3.0",
95
+ "documents.js": "^6.2.0",
96
96
  "ink": "^7.1.1",
97
97
  "ink-text-input": "^6.0.0",
98
98
  "react": "^19.2.8"
@@ -106,7 +106,7 @@
106
106
  "eslint": "^10.8.0",
107
107
  "husky": "^9.1.7",
108
108
  "ink-testing-library": "^4.0.0",
109
- "odf.js": "^6.1.1",
109
+ "odf.js": "^6.1.2",
110
110
  "publint": "^0.3.22",
111
111
  "semantic-release": "^25.0.8",
112
112
  "tsdown": "^0.22.14",