@pecot/visual-mcp 3.1.1-dev.141 → 3.1.1-dev.143
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/.claude-plugin/plugin.json +1 -1
- package/cli/dist/commands/drawio/export.d.ts +9 -24
- package/cli/dist/commands/drawio/export.js +15 -135
- package/cli/dist/commands/drawio/theme.d.ts +3 -3
- package/cli/dist/commands/drawio/theme.js +10 -10
- package/cli/dist/commands/drawio/url.d.ts +9 -26
- package/cli/dist/commands/drawio/url.js +18 -131
- package/cli/dist/commands/evidence-xlsx/create.d.ts +4 -12
- package/cli/dist/commands/evidence-xlsx/create.js +9 -92
- package/cli/dist/commands/slidev-project/create.d.ts +5 -30
- package/cli/dist/commands/slidev-project/create.js +12 -136
- package/cli/dist/commands/slidev-project/linked-theme.d.ts +1 -1
- package/cli/dist/commands/slidev-project/linked-theme.js +2 -2
- package/cli/dist/commands/slidev-project/lint.d.ts +8 -37
- package/cli/dist/commands/slidev-project/lint.js +16 -161
- package/cli/dist/commands/slidev-project/sync.d.ts +7 -26
- package/cli/dist/commands/slidev-project/sync.js +15 -156
- package/cli/dist/commands/slidev-project/theme.d.ts +2 -13
- package/cli/dist/commands/slidev-project/theme.js +3 -93
- package/cli/dist/commands/slidev-to-pptx/convert.d.ts +10 -17
- package/cli/dist/commands/slidev-to-pptx/convert.js +25 -266
- package/cli/dist/diagnostics.d.ts +0 -4
- package/cli/dist/diagnostics.js +0 -6
- package/cli/dist/domain/_shared/failure-kind.d.ts +2 -2
- package/cli/dist/domain/_shared/failure-kind.js +2 -2
- package/cli/dist/domain/_shared/ports.d.ts +3 -4
- package/cli/dist/domain/evidence-xlsx/image-dimensions.d.ts +1 -1
- package/cli/dist/domain/pptx-ooxml/preview-normalize.d.ts +0 -12
- package/cli/dist/domain/pptx-ooxml/preview-normalize.js +1 -25
- package/cli/dist/domain/slidev-project/errors.js +2 -2
- package/cli/dist/domain/slidev-project/generated-files.js +3 -3
- package/cli/dist/domain/slidev-project/lint.d.ts +7 -7
- package/cli/dist/domain/slidev-project/lint.js +8 -8
- package/cli/dist/domain/slidev-project/package-json.d.ts +1 -1
- package/cli/dist/domain/slidev-project/package-json.js +2 -2
- package/cli/dist/domain/slidev-project/sync.d.ts +11 -11
- package/cli/dist/domain/slidev-project/sync.js +18 -19
- package/cli/dist/domain/slidev-theme/deck-lint-input.js +1 -1
- package/cli/dist/domain/slidev-theme/declaration.js +1 -1
- package/cli/dist/domain/slidev-theme/skeleton.js +1 -1
- package/cli/dist/domain/slidev-theme/talk-theme.d.ts +3 -3
- package/cli/dist/domain/slidev-theme/talk-theme.js +5 -7
- package/cli/dist/domain/slidev-to-pptx/config.d.ts +1 -1
- package/cli/dist/domain/slidev-to-pptx/config.js +1 -1
- package/cli/dist/domain/slidev-to-pptx/errors.d.ts +4 -4
- package/cli/dist/domain/slidev-to-pptx/errors.js +4 -4
- package/cli/dist/domain/slidev-to-pptx/types.d.ts +1 -1
- package/cli/dist/infra/_shared/dependency-root.d.ts +9 -67
- package/cli/dist/infra/_shared/dependency-root.js +15 -126
- package/cli/dist/infra/_shared/flock.js +1 -2
- package/cli/dist/infra/_shared/plugin-root.d.ts +3 -5
- package/cli/dist/infra/_shared/plugin-root.js +5 -12
- package/cli/dist/infra/evidence-xlsx/workbook-writer.d.ts +1 -1
- package/cli/dist/infra/playwright/chromium.d.ts +4 -15
- package/cli/dist/infra/playwright/chromium.js +6 -18
- package/cli/dist/infra/playwright/host-dependencies.d.ts +2 -2
- package/cli/dist/infra/playwright/host-dependencies.js +6 -6
- package/cli/dist/infra/pptx-ooxml/soffice.js +1 -1
- package/cli/dist/infra/slidev-project/eslint-runner.d.ts +1 -1
- package/cli/dist/infra/slidev-project/eslint-runner.js +2 -2
- package/cli/dist/infra/slidev-to-pptx/index.js +1 -1
- package/cli/dist/infra/slidev-to-pptx/pipeline.js +1 -1
- package/cli/dist/infra/slidev-to-pptx/prerender-capture.js +1 -1
- package/cli/dist/infra/slidev-to-pptx/server.js +2 -2
- package/cli/dist/main.d.ts +3 -0
- package/cli/dist/main.js +28 -0
- package/cli/dist/mcp/result.d.ts +5 -1
- package/cli/dist/mcp/result.js +9 -1
- package/cli/dist/mcp/serve.d.ts +2 -3
- package/cli/dist/mcp/serve.js +4 -5
- package/cli/dist/mcp/server.d.ts +5 -1
- package/cli/dist/mcp/server.js +10 -7
- package/cli/dist/mcp/tool-names.js +4 -1
- package/cli/dist/mcp/tools/_shared.d.ts +1 -1
- package/cli/dist/mcp/tools/_shared.js +2 -2
- package/cli/dist/mcp/tools/drawio.js +12 -15
- package/cli/dist/mcp/tools/evidence.js +2 -2
- package/cli/dist/mcp/tools/file.d.ts +31 -0
- package/cli/dist/mcp/tools/file.js +482 -0
- package/cli/dist/mcp/tools/index.d.ts +1 -1
- package/cli/dist/mcp/tools/index.js +6 -3
- package/cli/dist/mcp/tools/setup.js +3 -3
- package/cli/dist/mcp/tools/slide-dev.js +6 -7
- package/cli/dist/mcp/tools/slide-page.js +3 -3
- package/cli/dist/mcp/tools/slide-theme.d.ts +0 -1
- package/cli/dist/mcp/tools/slide-theme.js +2 -3
- package/cli/dist/mcp/tools/slide.d.ts +4 -4
- package/cli/dist/mcp/tools/slide.js +13 -14
- package/cli/dist/node-runtime.d.ts +2 -2
- package/cli/dist/node-runtime.js +4 -13
- package/cli/dist/version.d.ts +1 -8
- package/cli/dist/version.js +2 -11
- package/npm-shrinkwrap.json +7 -17
- package/package.json +2 -3
- package/bin/pecot-visual-mcp.mjs +0 -10
- package/cli/dist/cli.d.ts +0 -5
- package/cli/dist/cli.js +0 -109
- package/cli/dist/commands/chromium/host-dependencies.d.ts +0 -18
- package/cli/dist/commands/chromium/host-dependencies.js +0 -75
- package/cli/dist/commands/pptx-ooxml/preview.d.ts +0 -74
- package/cli/dist/commands/pptx-ooxml/preview.js +0 -399
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
// `pecotv pptx preview` 実装。
|
|
2
|
-
// dom-to-pptx 2.1.1 の `wrap="none"` + `<a:spAutoFit/>` を LibreOffice が中心基準 auto-size で描画する。
|
|
3
|
-
// この既知差異を補正したプレビュー PDF を生成する。
|
|
4
|
-
//
|
|
5
|
-
// 元 PPTX は一切変更しない。
|
|
6
|
-
// 全 entry を読み取り、slide part のみプレビュー正規化 (noAutofit + wrap=square) して mkdtemp に一時 PPTX を書き出す。
|
|
7
|
-
// soffice で PDF 化して --out へ copy する。一時 dir は finally で必ず削除する。
|
|
8
|
-
// 成果物生成ルート (slide convert) には組み込まない。
|
|
9
|
-
import { performance } from 'node:perf_hooks';
|
|
10
|
-
import { createHash } from 'node:crypto';
|
|
11
|
-
import { copyFile, mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
12
|
-
import { tmpdir } from 'node:os';
|
|
13
|
-
import path from 'node:path';
|
|
14
|
-
import { Readable } from 'node:stream';
|
|
15
|
-
import { Command } from 'commander';
|
|
16
|
-
import { applyPreviewNormalization, detectPreviewDivergence, } from '../../domain/pptx-ooxml/preview-normalize.js';
|
|
17
|
-
import { createDiagnostics, passthrough, writeData } from '../../diagnostics.js';
|
|
18
|
-
import { XmldomXmlEngine } from '../../infra/pptx-ooxml/xml-engine.js';
|
|
19
|
-
import { YauzlYazlPptxArchive } from '../../infra/pptx-ooxml/archive.js';
|
|
20
|
-
import { SofficePdfConverter, SofficeSpawnError, SofficeTimeoutError, } from '../../infra/pptx-ooxml/soffice.js';
|
|
21
|
-
const SLIDE_PART_REGEX = /^ppt\/slides\/slide(\d+)\.xml$/;
|
|
22
|
-
const SOFFICE_TIMEOUT_MS = 120_000;
|
|
23
|
-
export class PreviewRuntimeError extends Error {
|
|
24
|
-
reason;
|
|
25
|
-
constructor(message, reason) {
|
|
26
|
-
super(message);
|
|
27
|
-
this.reason = reason;
|
|
28
|
-
this.name = 'PreviewRuntimeError';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function formatError(error) {
|
|
32
|
-
/* c8 ignore next -- 非 Error 例外は本実装範囲では未発生、防御網のみ */
|
|
33
|
-
return error instanceof Error ? error.message : String(error);
|
|
34
|
-
}
|
|
35
|
-
function slideNumberOf(part) {
|
|
36
|
-
const match = SLIDE_PART_REGEX.exec(part);
|
|
37
|
-
/* c8 ignore next 2 -- 呼び出し元が SLIDE_PART_REGEX.test 済の part のみ渡すため null / 捕捉群未定義は到達不能 */
|
|
38
|
-
return match?.[1] === undefined ? 0 : Math.trunc(Number(match[1]));
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
入力 PPTX の全 entry を読み取り、slide part をプレビュー正規化して一時 PPTX を書き出す。
|
|
42
|
-
findings(slide 番号付き)と書き出した一時 PPTX path を返す。入力は read-only。
|
|
43
|
-
*/
|
|
44
|
-
async function buildNormalizedPptx(inputAbs, temporaryPptxPath,
|
|
45
|
-
// PptxArchive / XmlEngine の内部 method が mutable とみなされるため、interface readonly fields のみで担保。
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
47
|
-
dependencies) {
|
|
48
|
-
const reader = await openInput(inputAbs, async (inputPath) => dependencies.archive.read(inputPath));
|
|
49
|
-
const writer = dependencies.archive.write();
|
|
50
|
-
const findings = [];
|
|
51
|
-
let normalized = 0;
|
|
52
|
-
try {
|
|
53
|
-
// slide part のみ正規化対象としてバッファ収集する。
|
|
54
|
-
// それ以外 (rels / media / presentation.xml 等) は lazy passthrough で writer に積み直す。
|
|
55
|
-
// 目的は media・presentation.xml の脱落防止。
|
|
56
|
-
// 本コマンドは rels を mutate しないため、slide と非 slide の 2 分類で足りる。
|
|
57
|
-
const slideBuffers = new Map();
|
|
58
|
-
for await (const entry of reader.entries()) {
|
|
59
|
-
if (SLIDE_PART_REGEX.test(entry.part)) {
|
|
60
|
-
slideBuffers.set(entry.part, await entry.read());
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
// media (大型バイナリ) を全件メモリ展開しないよう、addReadStream で
|
|
64
|
-
// finish 時に 1 件ずつ pull する lazy passthrough にする。read は
|
|
65
|
-
// pull 時まで遅延する (finish は reader.close より前の try 内で呼ばれるため
|
|
66
|
-
// pull 時に reader は open)。
|
|
67
|
-
const entryReadThunk = entry.read.bind(entry);
|
|
68
|
-
writer.addReadStream(entry.part, () => Readable.from((async function* () {
|
|
69
|
-
yield await entryReadThunk();
|
|
70
|
-
})()));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
for (const [slidePart, slideBuffer] of slideBuffers) {
|
|
74
|
-
const slideDocument = dependencies.engine.parse(slideBuffer);
|
|
75
|
-
const slide = slideNumberOf(slidePart);
|
|
76
|
-
for (const finding of detectPreviewDivergence(slideDocument)) {
|
|
77
|
-
findings.push(finding.shapeName === undefined
|
|
78
|
-
? { slide, rule: finding.rule }
|
|
79
|
-
: { slide, rule: finding.rule, shapeName: finding.shapeName });
|
|
80
|
-
}
|
|
81
|
-
const applied = applyPreviewNormalization(slideDocument);
|
|
82
|
-
normalized += applied.normalized;
|
|
83
|
-
writer.addBuffer(slidePart, dependencies.engine.serialize(slideDocument));
|
|
84
|
-
}
|
|
85
|
-
await writer.finish(temporaryPptxPath);
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
await reader.close();
|
|
89
|
-
}
|
|
90
|
-
// slide 番号昇順で安定化する (Map 反復順は挿入順 = archive 列挙順のため)。
|
|
91
|
-
findings.sort((a, b) => a.slide - b.slide);
|
|
92
|
-
return { findings, normalized };
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
入力を一切変更せず、全 entry を読み取って findings のみ収集する(--detect-only ルート)。
|
|
96
|
-
*/
|
|
97
|
-
async function detectOnly(inputAbs,
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- 同上
|
|
99
|
-
dependencies) {
|
|
100
|
-
const reader = await openInput(inputAbs, async (inputPath) => dependencies.archive.read(inputPath));
|
|
101
|
-
const findings = [];
|
|
102
|
-
try {
|
|
103
|
-
for await (const entry of reader.entries()) {
|
|
104
|
-
if (!SLIDE_PART_REGEX.test(entry.part))
|
|
105
|
-
continue;
|
|
106
|
-
const slideDocument = dependencies.engine.parse(await entry.read());
|
|
107
|
-
const slide = slideNumberOf(entry.part);
|
|
108
|
-
for (const finding of detectPreviewDivergence(slideDocument)) {
|
|
109
|
-
findings.push(finding.shapeName === undefined
|
|
110
|
-
? { slide, rule: finding.rule }
|
|
111
|
-
: { slide, rule: finding.rule, shapeName: finding.shapeName });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
finally {
|
|
116
|
-
await reader.close();
|
|
117
|
-
}
|
|
118
|
-
findings.sort((a, b) => a.slide - b.slide);
|
|
119
|
-
return findings;
|
|
120
|
-
}
|
|
121
|
-
async function sha256Of(filePath) {
|
|
122
|
-
const buffer = await readFile(filePath);
|
|
123
|
-
return createHash('sha256').update(buffer).digest('hex');
|
|
124
|
-
}
|
|
125
|
-
function inputOpenFailure(inputAbs, error) {
|
|
126
|
-
return new PreviewRuntimeError(`cannot open input PPTX: ${inputAbs}: ${formatError(error)}`, 'input-open-failed');
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
入力 PPTX の sha256。入力が無い・読めない場合は input-open-failed に倒す。
|
|
130
|
-
*/
|
|
131
|
-
async function inputSha256Of(inputAbs) {
|
|
132
|
-
try {
|
|
133
|
-
return await sha256Of(inputAbs);
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
throw inputOpenFailure(inputAbs, error);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
入力 PPTX を開く。PDF ルート・detect-only ルートともに runPreview 冒頭の sha256Of が先に
|
|
141
|
-
input-open-failed を投げるため、ここでの失敗は到達不能な防御網。
|
|
142
|
-
*/
|
|
143
|
-
async function openInput(inputAbs, read) {
|
|
144
|
-
try {
|
|
145
|
-
return await read(inputAbs);
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
/* c8 ignore next 2 -- 上記のとおり到達不能。防御網 */
|
|
149
|
-
throw inputOpenFailure(inputAbs, error);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
export async function runPreview(inputPath, options,
|
|
153
|
-
// PptxArchive / XmlEngine / PdfConverter の内部 method は mutable とみなされる。
|
|
154
|
-
// そのため interface の readonly fields のみで担保する。
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
156
|
-
dependencies) {
|
|
157
|
-
const inputAbs = path.resolve(inputPath);
|
|
158
|
-
const start = dependencies.now();
|
|
159
|
-
const isDetectOnlyMode = options.detectOnly === true;
|
|
160
|
-
if (isDetectOnlyMode) {
|
|
161
|
-
// 入力不変を通常ルートと対称に sha256 で担保する (read-only 設計だが「入力不変」を売りにするため)。
|
|
162
|
-
// 入力不在もここで input-open-failed に倒す (archive.read より前に読むため)。
|
|
163
|
-
const detectInputSha = await inputSha256Of(inputAbs);
|
|
164
|
-
const findings = await detectOnly(inputAbs, dependencies);
|
|
165
|
-
const detectAfterSha = await sha256Of(inputAbs);
|
|
166
|
-
/* c8 ignore next 6 -- detect-only は read-only 設計のため sha 変化ルートは到達不能。Acceptance 3 の防御網 */
|
|
167
|
-
if (detectAfterSha !== detectInputSha) {
|
|
168
|
-
throw new PreviewRuntimeError(`input PPTX changed (sha256 mismatch): ${inputAbs}`, 'input-mutated');
|
|
169
|
-
}
|
|
170
|
-
const summary = {
|
|
171
|
-
inputAbs,
|
|
172
|
-
findings,
|
|
173
|
-
normalized: 0,
|
|
174
|
-
detectOnly: true,
|
|
175
|
-
durationMs: dependencies.now() - start,
|
|
176
|
-
};
|
|
177
|
-
await writeReport(options.report, summary);
|
|
178
|
-
return summary;
|
|
179
|
-
}
|
|
180
|
-
// Acceptance 3 (入力不変) の二重担保: 実行前後の sha256 を比較する。
|
|
181
|
-
// 入力不在もここで input-open-failed に倒す (archive.read より前に読むため)。
|
|
182
|
-
const inputSha = await inputSha256Of(inputAbs);
|
|
183
|
-
const stem = path.basename(inputAbs, path.extname(inputAbs));
|
|
184
|
-
const outputAbs = options.out === undefined
|
|
185
|
-
? path.join(path.dirname(inputAbs), `${stem}.preview.pdf`)
|
|
186
|
-
: path.resolve(options.out);
|
|
187
|
-
const temporaryDirectory = await mkdtemp(path.join(tmpdir(), 'pecotv-pptx-preview-'));
|
|
188
|
-
try {
|
|
189
|
-
// soffice の PDF 名が入力 stem 依存のため、一時 PPTX も同 stem で書き出す。
|
|
190
|
-
const temporaryPptx = path.join(temporaryDirectory, `${stem}.pptx`);
|
|
191
|
-
const { findings, normalized } = await buildNormalizedPptx(inputAbs, temporaryPptx, dependencies);
|
|
192
|
-
const pdfOutputDirectory = path.join(temporaryDirectory, 'pdf');
|
|
193
|
-
await mkdir(pdfOutputDirectory, { recursive: true });
|
|
194
|
-
const pdfPath = await convertToPdf(temporaryPptx, pdfOutputDirectory, dependencies);
|
|
195
|
-
await mkdir(path.dirname(outputAbs), { recursive: true });
|
|
196
|
-
await copyFile(pdfPath, outputAbs);
|
|
197
|
-
// 入力不変を最終確認する。
|
|
198
|
-
const afterSha = await sha256Of(inputAbs);
|
|
199
|
-
/* c8 ignore next 6 -- 入力は read-only 設計のため sha 変化ルートは到達不能。Acceptance 3 の防御網 */
|
|
200
|
-
if (afterSha !== inputSha) {
|
|
201
|
-
throw new PreviewRuntimeError(`input PPTX changed (sha256 mismatch): ${inputAbs}`, 'input-mutated');
|
|
202
|
-
}
|
|
203
|
-
const summary = {
|
|
204
|
-
inputAbs,
|
|
205
|
-
outputAbs,
|
|
206
|
-
findings,
|
|
207
|
-
normalized,
|
|
208
|
-
detectOnly: false,
|
|
209
|
-
durationMs: dependencies.now() - start,
|
|
210
|
-
};
|
|
211
|
-
await writeReport(options.report, summary);
|
|
212
|
-
return summary;
|
|
213
|
-
}
|
|
214
|
-
finally {
|
|
215
|
-
await rm(temporaryDirectory, { recursive: true, force: true });
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
async function convertToPdf(temporaryPptx, pdfOutputDirectory,
|
|
219
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- 同上
|
|
220
|
-
dependencies) {
|
|
221
|
-
let result;
|
|
222
|
-
try {
|
|
223
|
-
result = await dependencies.pdfConverter.convertToPdf({
|
|
224
|
-
inputPath: temporaryPptx,
|
|
225
|
-
outputDirectory: pdfOutputDirectory,
|
|
226
|
-
timeoutMs: SOFFICE_TIMEOUT_MS,
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
if (error instanceof SofficeTimeoutError) {
|
|
231
|
-
throw new PreviewRuntimeError(`soffice PDF conversion timed out after ${String(error.timeoutMs)}ms`, 'soffice-timeout');
|
|
232
|
-
}
|
|
233
|
-
if (error instanceof SofficeSpawnError) {
|
|
234
|
-
throw new PreviewRuntimeError(`soffice (LibreOffice) is not installed; run 'sudo apt-get install -y libreoffice-impress'`
|
|
235
|
-
+ `: ${error.stderr}`, 'soffice-not-found');
|
|
236
|
-
}
|
|
237
|
-
/* c8 ignore next 5 -- PdfConverter は SofficeSpawnError / SofficeTimeoutError 以外を投げない契約。防御網 */
|
|
238
|
-
throw new PreviewRuntimeError(`PDF conversion failed: ${formatError(error)}`, 'soffice-conversion-failed');
|
|
239
|
-
}
|
|
240
|
-
// soffice は変換失敗でも exit 0 を返すため、PDF の実在・非空を必須条件とする。
|
|
241
|
-
// soffice 本体 (libreoffice-core) だけが入った環境では PPTX を load できず、
|
|
242
|
-
// exit 0 + PDF 不在でこのルートに来る (#1072)。案内は soffice-not-found ではなく
|
|
243
|
-
// ここに置かないと利用者に届かない。
|
|
244
|
-
const pdfSize = await pdfFileSize(result.pdfPath);
|
|
245
|
-
if (pdfSize === 0) {
|
|
246
|
-
throw new PreviewRuntimeError(`soffice did not produce a PDF (output PDF missing or empty): ${result.pdfPath}`
|
|
247
|
-
+ `; PPTX conversion requires libreoffice-impress`
|
|
248
|
-
+ ` ('sudo apt-get install -y libreoffice-impress')`, 'soffice-conversion-failed');
|
|
249
|
-
}
|
|
250
|
-
return result.pdfPath;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
PDF の byte size を返す。不在なら 0(= 変換失敗扱い)。
|
|
254
|
-
*/
|
|
255
|
-
async function pdfFileSize(pdfPath) {
|
|
256
|
-
try {
|
|
257
|
-
const pdfStat = await stat(pdfPath);
|
|
258
|
-
return pdfStat.size;
|
|
259
|
-
}
|
|
260
|
-
catch {
|
|
261
|
-
return 0;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async function writeReport(reportPath, summary) {
|
|
265
|
-
if (reportPath === undefined)
|
|
266
|
-
return;
|
|
267
|
-
const reportAbs = path.resolve(reportPath);
|
|
268
|
-
const payload = JSON.stringify({
|
|
269
|
-
input: summary.inputAbs,
|
|
270
|
-
output: summary.outputAbs,
|
|
271
|
-
detectOnly: summary.detectOnly,
|
|
272
|
-
normalized: summary.normalized,
|
|
273
|
-
findings: summary.findings,
|
|
274
|
-
durationMs: summary.durationMs,
|
|
275
|
-
}, undefined, 2);
|
|
276
|
-
await mkdir(path.dirname(reportAbs), { recursive: true });
|
|
277
|
-
await writeFile(reportAbs, payload, 'utf8');
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
プレビューを実行し、`--json` と同形の結果オブジェクトを返す。
|
|
281
|
-
CLI の action と MCP ツールはどちらもこの関数を呼ぶ (実行と結果組み立ての単一実装)。
|
|
282
|
-
*/
|
|
283
|
-
export async function executePptxPreview(options,
|
|
284
|
-
// PptxArchive / XmlEngine / PdfConverter の内部 method は mutable とみなされる。
|
|
285
|
-
// そのため interface の readonly fields のみで担保する。
|
|
286
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
287
|
-
dependencies) {
|
|
288
|
-
const summary = await runPreview(options.input, {
|
|
289
|
-
detectOnly: options.detectOnly,
|
|
290
|
-
...(options.out !== undefined && { out: options.out }),
|
|
291
|
-
...(options.report !== undefined && { report: options.report }),
|
|
292
|
-
}, dependencies);
|
|
293
|
-
return {
|
|
294
|
-
event: 'pptx.preview.done',
|
|
295
|
-
input: summary.inputAbs,
|
|
296
|
-
...(summary.outputAbs !== undefined && { output: summary.outputAbs }),
|
|
297
|
-
detectOnly: summary.detectOnly,
|
|
298
|
-
normalized: summary.normalized,
|
|
299
|
-
findings: summary.findings,
|
|
300
|
-
durationMs: summary.durationMs,
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
実行失敗時の exit code。usage エラー (exit 2) は commander が cli.ts の main へ委譲するため、
|
|
305
|
-
本コマンド自身が設定するのは 1 のみ。
|
|
306
|
-
*/
|
|
307
|
-
export const PPTX_PREVIEW_FAILURE_EXIT_CODE = 1;
|
|
308
|
-
export function errorToReason(error) {
|
|
309
|
-
/* c8 ignore next -- unknown フォールバックは防御網 */
|
|
310
|
-
return error instanceof PreviewRuntimeError ? error.reason : 'unknown';
|
|
311
|
-
}
|
|
312
|
-
function formatFindingLine(finding) {
|
|
313
|
-
const shape = finding.shapeName === undefined ? '(unnamed)' : `"${finding.shapeName}"`;
|
|
314
|
-
return `slide ${String(finding.slide)}: shape ${shape}`
|
|
315
|
-
+ ` — spAutoFit + wrap=none (known LibreOffice centered-rendering difference)`;
|
|
316
|
-
}
|
|
317
|
-
function doesArgvWantJson(argv) {
|
|
318
|
-
return argv.includes('--json');
|
|
319
|
-
}
|
|
320
|
-
export function createPptxPreviewCommand(buildDependencies) {
|
|
321
|
-
const command = new Command('preview')
|
|
322
|
-
.description('generate a preview PDF of a PPTX, correcting LibreOffice rendering differences; the original PPTX is not modified')
|
|
323
|
-
.argument('<input>', 'input .pptx path')
|
|
324
|
-
.option('--out <path>', 'output .pdf path (default: <input-dir>/<input-stem>.preview.pdf)')
|
|
325
|
-
.option('--json', 'emit machine-readable result on stdout', false)
|
|
326
|
-
.option('--report <path>', 'write findings JSON to <path>')
|
|
327
|
-
.option('--detect-only', 'print only the detection report without calling soffice', false)
|
|
328
|
-
.exitOverride()
|
|
329
|
-
.configureOutput({
|
|
330
|
-
writeErr: (string_) => {
|
|
331
|
-
const dependencies = buildDependencies();
|
|
332
|
-
if (doesArgvWantJson(process.argv)) {
|
|
333
|
-
writeData(dependencies.stdout, JSON.stringify({
|
|
334
|
-
event: 'pptx.preview.error',
|
|
335
|
-
reason: 'invalid-option',
|
|
336
|
-
detail: string_.replace(/^error:\s*/i, '').trim(),
|
|
337
|
-
}));
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
passthrough(dependencies.stderr, string_);
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
})
|
|
344
|
-
.action(async (input, raw) => {
|
|
345
|
-
const dependencies = buildDependencies();
|
|
346
|
-
const isJson = raw['json'] === true;
|
|
347
|
-
try {
|
|
348
|
-
const data = await executePptxPreview({
|
|
349
|
-
input,
|
|
350
|
-
detectOnly: raw['detectOnly'] === true,
|
|
351
|
-
...((typeof raw['out'] === 'string') && { out: raw['out'] }),
|
|
352
|
-
...((typeof raw['report'] === 'string') && { report: raw['report'] }),
|
|
353
|
-
}, dependencies);
|
|
354
|
-
emitSuccess(dependencies, isJson, data);
|
|
355
|
-
}
|
|
356
|
-
catch (error) {
|
|
357
|
-
const detail = formatError(error);
|
|
358
|
-
if (isJson) {
|
|
359
|
-
writeData(dependencies.stdout, JSON.stringify({
|
|
360
|
-
event: 'pptx.preview.error',
|
|
361
|
-
reason: errorToReason(error),
|
|
362
|
-
detail,
|
|
363
|
-
}));
|
|
364
|
-
}
|
|
365
|
-
else {
|
|
366
|
-
createDiagnostics(dependencies.stderr).error(`pptx preview: ${detail}`);
|
|
367
|
-
}
|
|
368
|
-
process.exitCode = PPTX_PREVIEW_FAILURE_EXIT_CODE;
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
return command;
|
|
372
|
-
}
|
|
373
|
-
function emitSuccess(
|
|
374
|
-
// WritableStream は内部 mutable。
|
|
375
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
376
|
-
dependencies, isJson, data) {
|
|
377
|
-
if (isJson) {
|
|
378
|
-
writeData(dependencies.stdout, JSON.stringify(data));
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
for (const finding of data.findings) {
|
|
382
|
-
writeData(dependencies.stdout, formatFindingLine(finding));
|
|
383
|
-
}
|
|
384
|
-
writeData(dependencies.stdout, data.detectOnly
|
|
385
|
-
? `pptx preview (detect-only): ${data.input} (${String(data.findings.length)} findings)`
|
|
386
|
-
: `pptx preview: ${data.input} -> ${data.output ?? ''}`
|
|
387
|
-
+ ` (${String(data.findings.length)} findings, ${String(data.normalized)} normalized)`);
|
|
388
|
-
}
|
|
389
|
-
export function pptxPreviewDefaultDependencies() {
|
|
390
|
-
return {
|
|
391
|
-
archive: new YauzlYazlPptxArchive(),
|
|
392
|
-
engine: new XmldomXmlEngine(),
|
|
393
|
-
pdfConverter: new SofficePdfConverter(),
|
|
394
|
-
stdout: process.stdout,
|
|
395
|
-
stderr: process.stderr,
|
|
396
|
-
now: () => performance.now(),
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
//# sourceMappingURL=preview.js.map
|