pptx-glimpse 3.0.0 → 3.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.
package/dist/cli.d.cts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,195 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ convertPptxToPng,
4
+ convertPptxToSvg
5
+ } from "./chunk-XGCLQP2P.js";
6
+ import "./chunk-NMAO44T7.js";
7
+ import "./chunk-PGCREQQU.js";
8
+
9
+ // src/cli-runner.ts
10
+ import { mkdir, readFile, stat, writeFile } from "fs/promises";
11
+ import { basename, extname, resolve } from "path";
12
+ import { parseArgs } from "util";
13
+ var defaultConverters = {
14
+ convertPptxToSvg,
15
+ convertPptxToPng
16
+ };
17
+ var helpText = `Usage:
18
+ pptx-glimpse convert <file.pptx> [options]
19
+
20
+ Options:
21
+ --format <svg|png> Output format. Defaults to svg.
22
+ --slides <list> Comma-separated 1-based slide numbers, such as 1,3.
23
+ --out <dir> Output directory. Defaults to the current directory.
24
+ --log-level <level> Diagnostic output: off, warn, or debug. Defaults to warn.
25
+ --system-fonts Scan OS system font directories for better text fidelity.
26
+ -h, --help Show this help message.
27
+ `;
28
+ async function runCli(argv, options = {}) {
29
+ const cwd = options.cwd ?? process.cwd();
30
+ const streams = options.streams ?? { stdout: process.stdout, stderr: process.stderr };
31
+ const converters = options.converters ?? defaultConverters;
32
+ try {
33
+ if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h" || argv[0] === "help") {
34
+ streams.stdout.write(helpText);
35
+ return 0;
36
+ }
37
+ const [command, ...commandArgs] = argv;
38
+ if (command !== "convert") {
39
+ throw new CliUsageError(`Unknown command: ${command}`);
40
+ }
41
+ const commandOptions = parseConvertCommand(commandArgs, cwd);
42
+ await runConvertCommand(commandOptions, streams, converters);
43
+ return 0;
44
+ } catch (error) {
45
+ if (error instanceof CliHelpRequested) {
46
+ streams.stdout.write(helpText);
47
+ return 0;
48
+ }
49
+ streams.stderr.write(`pptx-glimpse: ${formatError(error)}
50
+ `);
51
+ return 1;
52
+ }
53
+ }
54
+ function parseConvertCommand(args, cwd) {
55
+ let parsed;
56
+ try {
57
+ parsed = parseArgs({
58
+ args: [...args],
59
+ allowPositionals: true,
60
+ options: {
61
+ format: { type: "string" },
62
+ slides: { type: "string" },
63
+ out: { type: "string" },
64
+ "log-level": { type: "string" },
65
+ "system-fonts": { type: "boolean" },
66
+ help: { type: "boolean", short: "h" }
67
+ }
68
+ });
69
+ } catch (error) {
70
+ throw new CliUsageError(formatError(error));
71
+ }
72
+ if (parsed.values.help === true) {
73
+ throw new CliHelpRequested();
74
+ }
75
+ if (parsed.positionals.length !== 1) {
76
+ throw new CliUsageError("Expected exactly one PPTX input file.");
77
+ }
78
+ const format = parseFormat(stringOption(parsed.values.format, "--format"));
79
+ const logLevel = parseLogLevel(stringOption(parsed.values["log-level"], "--log-level"));
80
+ const slides = parseSlides(stringOption(parsed.values.slides, "--slides"));
81
+ const outputDir = resolve(cwd, stringOption(parsed.values.out, "--out") ?? ".");
82
+ return {
83
+ inputPath: resolve(cwd, parsed.positionals[0]),
84
+ outputDir,
85
+ format,
86
+ ...slides !== void 0 ? { slides } : {},
87
+ logLevel,
88
+ systemFonts: parsed.values["system-fonts"] === true
89
+ };
90
+ }
91
+ async function runConvertCommand(options, streams, converters) {
92
+ await assertReadableFile(options.inputPath);
93
+ await mkdir(options.outputDir, { recursive: true });
94
+ const input = await readFile(options.inputPath);
95
+ const basenameWithoutExtension = basename(options.inputPath, extname(options.inputPath));
96
+ const conversionOptions = {
97
+ // Route diagnostics through the CLI streams below instead of converter console output.
98
+ logLevel: "off",
99
+ skipSystemFonts: !options.systemFonts,
100
+ ...options.slides !== void 0 ? { slides: options.slides } : {}
101
+ };
102
+ if (options.format === "png") {
103
+ const report2 = await converters.convertPptxToPng(input, conversionOptions);
104
+ for (const slide of report2.slides) {
105
+ const outputPath = resolve(
106
+ options.outputDir,
107
+ `${basenameWithoutExtension}-slide${slide.slideNumber}.png`
108
+ );
109
+ await writeFile(outputPath, slide.png);
110
+ streams.stdout.write(`${outputPath}
111
+ `);
112
+ }
113
+ printDiagnostics(report2, options.logLevel, streams.stderr);
114
+ return;
115
+ }
116
+ const report = await converters.convertPptxToSvg(input, conversionOptions);
117
+ for (const slide of report.slides) {
118
+ const outputPath = resolve(
119
+ options.outputDir,
120
+ `${basenameWithoutExtension}-slide${slide.slideNumber}.svg`
121
+ );
122
+ await writeFile(outputPath, slide.svg, "utf8");
123
+ streams.stdout.write(`${outputPath}
124
+ `);
125
+ }
126
+ printDiagnostics(report, options.logLevel, streams.stderr);
127
+ }
128
+ async function assertReadableFile(inputPath) {
129
+ try {
130
+ const inputStat = await stat(inputPath);
131
+ if (!inputStat.isFile()) {
132
+ throw new CliUsageError(`Input is not a file: ${inputPath}`);
133
+ }
134
+ } catch (error) {
135
+ if (error instanceof CliUsageError) throw error;
136
+ throw new CliUsageError(`Input file not found: ${inputPath}`);
137
+ }
138
+ }
139
+ function parseFormat(value) {
140
+ if (value === void 0) return "svg";
141
+ if (value === "svg" || value === "png") return value;
142
+ throw new CliUsageError(`Invalid --format value: ${value}. Expected svg or png.`);
143
+ }
144
+ function stringOption(value, name) {
145
+ if (value === void 0) return void 0;
146
+ if (typeof value === "string") return value;
147
+ throw new CliUsageError(`Invalid ${name} value.`);
148
+ }
149
+ function parseLogLevel(value) {
150
+ if (value === void 0) return "warn";
151
+ if (value === "off" || value === "warn" || value === "debug") return value;
152
+ throw new CliUsageError(`Invalid --log-level value: ${value}. Expected off, warn, or debug.`);
153
+ }
154
+ function parseSlides(value) {
155
+ if (value === void 0) return void 0;
156
+ const slides = value.split(",").map((part) => {
157
+ const trimmed = part.trim();
158
+ if (!/^[1-9]\d*$/.test(trimmed)) {
159
+ throw new CliUsageError(`Invalid --slides value: ${value}. Expected values like 1,3.`);
160
+ }
161
+ return Number(trimmed);
162
+ });
163
+ if (slides.length === 0) {
164
+ throw new CliUsageError("Expected at least one slide number.");
165
+ }
166
+ return slides;
167
+ }
168
+ function printDiagnostics(report, logLevel, stderr) {
169
+ if (logLevel === "off") return;
170
+ const warnings = report.diagnostics.filter((diagnostic) => diagnostic.severity === "warning");
171
+ if (warnings.length === 0) return;
172
+ stderr.write(`pptx-glimpse: ${warnings.length} warning(s)
173
+ `);
174
+ if (logLevel !== "debug") return;
175
+ for (const warning of warnings) {
176
+ const slide = warning.slideNumber !== void 0 ? ` slide ${warning.slideNumber}` : "";
177
+ stderr.write(`pptx-glimpse:${slide} ${warning.code}: ${warning.message}
178
+ `);
179
+ }
180
+ }
181
+ function formatError(error) {
182
+ return error instanceof Error ? error.message : String(error);
183
+ }
184
+ var CliUsageError = class extends Error {
185
+ };
186
+ var CliHelpRequested = class extends Error {
187
+ constructor() {
188
+ super(helpText);
189
+ }
190
+ };
191
+
192
+ // src/cli.ts
193
+ void runCli(process.argv.slice(2)).then((exitCode) => {
194
+ process.exitCode = exitCode;
195
+ });