@poe-platform/safe-bash 0.1.787 → 0.1.789
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 +1 -1
- package/dist/safe-bash/chunks/{chunk-WHURJBET.js → chunk-2MUJ7RLZ.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-PYTLIUST.js → chunk-CTUHLNJM.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-Z3HX3ZBA.js → chunk-D4PHJK4T.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-O6356Z27.js → chunk-H7MMJS26.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-Q3E6C3DX.js → chunk-KHJGUF2W.js} +14 -0
- package/dist/safe-bash/chunks/{chunk-FJZNUUOQ.js → chunk-VUVKC6HV.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-ZMYVCRAF.js → chunk-X5ZCECM6.js} +2 -2
- package/dist/safe-bash/chunks/{git-UFNPAOYZ.js → git-HO7WDPHZ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-PFBJR2PY.js → chunk-2KRKKW5S.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-4DSJDVBM.js → chunk-32F3RBUW.js} +10 -749
- package/dist/safe-bash/command-chunks/{chunk-WVWWRMFD.js → chunk-3KROFHBT.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-L3MLMXL4.js → chunk-3ZK5F23O.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-4QX6XCDD.js → chunk-4RNIZ3RT.js} +79 -0
- package/dist/safe-bash/command-chunks/{chunk-IFUNAM4D.js → chunk-5L62A5RO.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-D7TADAYG.js → chunk-64LG3EVJ.js} +17 -0
- package/dist/safe-bash/command-chunks/{chunk-JUDOV5MJ.js → chunk-6F7QJMJ3.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-IJ3FXP4Q.js → chunk-A3ZX6SCY.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DREUDEQG.js → chunk-AT6ZSOE6.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-BUKYQBXO.js → chunk-BJ6DGYJA.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-KSIGF4AG.js → chunk-BK4CMEE6.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-NSEUBSOD.js → chunk-CXMOCPPH.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-XGMWWUHV.js → chunk-CZ5DAK4K.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-Z57TV6TC.js → chunk-EZ2DTOLI.js} +4 -2
- package/dist/safe-bash/command-chunks/{chunk-ADCGH6A7.js → chunk-FH3D75FC.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WYJTWJZ5.js → chunk-G3G6W5ZE.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3HDIDEUJ.js → chunk-GF54KE2M.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3JS4FOLB.js → chunk-HETU7MYN.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-Z7TYZG3A.js → chunk-IHHTTQX6.js} +5 -3
- package/dist/safe-bash/command-chunks/{chunk-INDIFLBW.js → chunk-JTAGNROA.js} +4 -0
- package/dist/safe-bash/command-chunks/{chunk-Z47EO74H.js → chunk-MYKK3Q5G.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-GZOUGVVV.js → chunk-OYZ534IK.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-PGEYORBZ.js +25 -0
- package/dist/safe-bash/command-chunks/chunk-QM4UZF3C.js +753 -0
- package/dist/safe-bash/command-chunks/{chunk-TOSM3T3A.js → chunk-UJOO6DKY.js} +20 -9
- package/dist/safe-bash/command-chunks/{chunk-TFZEYNMX.js → chunk-VQLFJCG7.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-BIXN77VL.js → chunk-VUG324ER.js} +10 -0
- package/dist/safe-bash/command-chunks/{chunk-2LP3VMPA.js → chunk-WFDW4XXD.js} +1 -17
- package/dist/safe-bash/command-chunks/chunk-WR37IS4O.js +318 -0
- package/dist/safe-bash/command-chunks/{chunk-Y5IHIAY3.js → chunk-XNHSCU6I.js} +7 -3
- package/dist/safe-bash/commands/basic.js +148 -48
- package/dist/safe-bash/commands/bytes/compression/index.js +5 -6
- package/dist/safe-bash/commands/cmp.d.ts +2 -3
- package/dist/safe-bash/commands/cmp.js +2 -689
- package/dist/safe-bash/commands/docx/index.browser.js +3 -46
- package/dist/safe-bash/commands/docx/index.d.ts +2 -24
- package/dist/safe-bash/commands/docx/index.js +2 -41
- package/dist/safe-bash/commands/docx/io.d.ts +1 -14
- package/dist/safe-bash/commands/docx/io.js +1 -15
- package/dist/safe-bash/commands/llm/index.browser.js +3 -3
- package/dist/safe-bash/commands/network/index.browser.js +3 -3
- package/dist/safe-bash/commands/node/index.browser.js +3 -3
- package/dist/safe-bash/commands/pptx/index.d.ts +2 -28
- package/dist/safe-bash/commands/pptx/index.js +2 -152
- package/dist/safe-bash/commands/printf-float.d.ts +1 -0
- package/dist/safe-bash/commands/printf-float.js +48 -38
- package/dist/safe-bash/commands/printf-format.js +9 -6
- package/dist/safe-bash/commands/printf-quote.d.ts +3 -0
- package/dist/safe-bash/commands/printf-quote.js +62 -0
- package/dist/safe-bash/commands/printf-wide.d.ts +5 -0
- package/dist/safe-bash/commands/printf-wide.js +41 -0
- package/dist/safe-bash/commands/python/index.browser.js +2 -2
- package/dist/safe-bash/commands/truncate.d.ts +2 -3
- package/dist/safe-bash/commands/truncate.js +2 -686
- package/dist/safe-bash/contracts/diagnostics.d.ts +2 -0
- package/dist/safe-bash/contracts/diagnostics.js +2 -0
- package/dist/safe-bash/contracts/runtime-control.d.ts +2 -0
- package/dist/safe-bash/contracts/runtime-control.js +2 -0
- package/dist/safe-bash/core.browser.d.ts +1 -1
- package/dist/safe-bash/core.browser.js +2651 -4871
- package/dist/safe-bash/core.d.ts +10 -0
- package/dist/safe-bash/opt-in/commands/cmp/index.d.ts +6 -2
- package/dist/safe-bash/opt-in/commands/cmp/index.js +776 -79
- package/dist/safe-bash/opt-in/commands/cmp/options.d.ts +0 -12
- package/dist/safe-bash/opt-in/commands/cmp/options.js +0 -153
- package/dist/safe-bash/opt-in/commands/truncate/index.d.ts +8 -3
- package/dist/safe-bash/opt-in/commands/truncate/index.js +790 -272
- package/dist/safe-bash/opt-in/commands/truncate/sync.d.ts +1 -0
- package/dist/safe-bash/opt-in/commands/truncate/sync.js +60 -0
- package/dist/safe-bash/optional-host.browser.js +9 -1
- package/dist/safe-bash/optional-host.d.ts +3 -1
- package/dist/safe-bash/optional-host.js +3 -1
- package/dist/safe-bash/shell/runtime.js +10 -6
- package/dist/safe-bash-checksum-engine/index.d.ts +1 -1
- package/dist/safe-bash-checksum-engine/index.js +14 -2
- package/dist/safe-bash-command-bzip2/index.js +2 -1
- package/dist/safe-bash-command-cmp/index.d.ts +10 -0
- package/dist/safe-bash-command-cmp/index.js +796 -0
- package/dist/safe-bash-command-cmp/options.d.ts +12 -0
- package/dist/safe-bash-command-cmp/options.js +42 -0
- package/dist/safe-bash-command-csvcut/index.js +11 -8
- package/dist/safe-bash-command-csvgrep/index.js +35 -7
- package/dist/safe-bash-command-csvkit/codecs/python.js +4 -3
- package/dist/safe-bash-command-csvkit/codecs/utf8.js +3 -2
- package/dist/safe-bash-command-csvkit/index.js +80 -324
- package/dist/safe-bash-command-csvkit/python-regex.d.ts +5 -0
- package/dist/safe-bash-command-csvkit/python-regex.js +14 -0
- package/dist/safe-bash-command-csvkit/runtime.d.ts +1 -0
- package/dist/safe-bash-command-csvkit/sync-support.js +4 -2
- package/dist/safe-bash-command-diff3/index.js +3 -0
- package/dist/safe-bash-command-docx/LICENSE +21 -0
- package/dist/safe-bash-command-docx/index.d.ts +30 -0
- package/dist/safe-bash-command-docx/index.js +67 -0
- package/dist/safe-bash-command-docx/io.d.ts +14 -0
- package/dist/safe-bash-command-docx/io.js +26 -0
- package/dist/safe-bash-command-envsubst/index.js +34 -3
- package/dist/safe-bash-command-exiftool/index.js +3 -0
- package/dist/safe-bash-command-ffmpeg/index.js +1102 -1088
- package/dist/safe-bash-command-fold/family.js +1 -1
- package/dist/safe-bash-command-fold/index.js +1 -1
- package/dist/safe-bash-command-htmlq/index.js +5 -0
- package/dist/safe-bash-command-imagemagick/index.d.ts +25 -21
- package/dist/safe-bash-command-imagemagick/index.js +669 -271
- package/dist/safe-bash-command-mmdc/index.js +48 -10
- package/dist/safe-bash-command-mmdc/svg.d.ts +1 -0
- package/dist/safe-bash-command-op/index.js +19 -14
- package/dist/safe-bash-command-pandoc/command.js +1 -1
- package/dist/safe-bash-command-pandoc/index.js +1 -1
- package/dist/safe-bash-command-pdfimages/index.d.ts +7 -1
- package/dist/safe-bash-command-pdfimages/index.js +63 -33
- package/dist/safe-bash-command-pdfinfo/index.d.ts +24 -20
- package/dist/safe-bash-command-pdfinfo/index.js +370 -161
- package/dist/safe-bash-command-pdftk/index.d.ts +7 -3
- package/dist/safe-bash-command-pdftk/index.js +114 -45
- package/dist/safe-bash-command-pdftoppm/index.d.ts +15 -7
- package/dist/safe-bash-command-pdftoppm/index.js +179 -109
- package/dist/safe-bash-command-pdftotext/index.d.ts +9 -5
- package/dist/safe-bash-command-pdftotext/index.js +90 -27
- package/dist/safe-bash-command-pptx/LICENSE +21 -0
- package/dist/safe-bash-command-pptx/index.d.ts +33 -0
- package/dist/safe-bash-command-pptx/index.js +168 -0
- package/dist/safe-bash-command-qpdf/index.d.ts +9 -3
- package/dist/safe-bash-command-qpdf/index.js +80 -29
- package/dist/safe-bash-command-sha512sum/index.js +12 -475
- package/dist/safe-bash-command-sips/index.d.ts +9 -5
- package/dist/safe-bash-command-sips/index.js +63 -44
- package/dist/safe-bash-command-soffice/index.d.ts +9 -3
- package/dist/safe-bash-command-soffice/index.js +65 -24
- package/dist/safe-bash-command-sqlite3/engine.d.ts +9 -0
- package/dist/safe-bash-command-sqlite3/index.d.ts +1 -0
- package/dist/safe-bash-command-sqlite3/index.js +851 -352
- package/dist/safe-bash-command-ssconvert/formats/xls.js +3 -3
- package/dist/safe-bash-command-timeout/index.js +3 -3
- package/dist/safe-bash-command-truncate/index.d.ts +8 -3
- package/dist/safe-bash-command-truncate/index.js +790 -272
- package/dist/safe-bash-command-truncate/sync.d.ts +1 -0
- package/dist/safe-bash-command-truncate/sync.js +60 -0
- package/dist/safe-bash-command-wkhtmltopdf/index.js +92 -38
- package/dist/safe-bash-command-wkhtmltopdf/pdf-renderer.d.ts +1 -1
- package/dist/safe-bash-command-xxd/index.js +78 -20
- package/dist/safe-bash-command-xz/command.d.ts +4 -0
- package/dist/safe-bash-command-xz/index.d.ts +1 -1
- package/dist/safe-bash-command-xz/index.js +1 -1
- package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
- package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
- package/dist/safe-bash-compression-engine/files.js +6 -6
- package/dist/safe-bash-compression-engine/index.js +5 -5
- package/dist/safe-bash-compression-engine/operand.js +6 -6
- package/dist/safe-bash-compression-engine/stream.js +5 -5
- package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
- package/dist/safe-bash-contracts/command.js +3 -3
- package/dist/safe-bash-contracts/diagnostics.js +3 -3
- package/dist/safe-bash-contracts/escaping.js +9 -9
- package/dist/safe-bash-contracts/filesystem-descriptor.js +3 -3
- package/dist/safe-bash-contracts/filesystem-output.js +8 -8
- package/dist/safe-bash-contracts/index.js +21 -19
- package/dist/safe-bash-contracts/io.d.ts +12 -0
- package/dist/safe-bash-contracts/io.js +4 -1
- package/dist/safe-bash-contracts/output.js +3 -2
- package/dist/safe-bash-contracts/runtime-control.js +2 -2
- package/dist/safe-bash-contracts/signals.js +1 -1
- package/dist/safe-bash-contracts/yield.d.ts +1 -0
- package/dist/safe-bash-contracts/yield.js +3 -1
- package/dist/safe-bash-csv-engine/index.d.ts +10 -1
- package/dist/safe-bash-csv-engine/index.js +78 -6
- package/dist/safe-bash-io-engine/commands/search/requirements.js +3 -3
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +3 -3
- package/dist/safe-bash-io-engine/gnu-information.js +1 -1
- package/dist/safe-bash-io-engine/internal.d.ts +1 -1
- package/dist/safe-bash-io-engine/internal.js +2 -2
- package/dist/safe-bash-mcp/index.browser.d.ts +875 -0
- package/dist/safe-bash-mcp/index.browser.js +8740 -0
- package/dist/safe-bash-mcp/index.js +32 -31
- package/dist/safe-bash-query-engine/capture.js +3 -3
- package/dist/safe-bash-query-engine/delpaths.js +3 -3
- package/dist/safe-bash-query-engine/formats.js +2 -2
- package/dist/safe-bash-query-engine/index.js +12 -12
- package/dist/safe-bash-query-engine/indices.js +3 -3
- package/dist/safe-bash-query-engine/input.js +1 -1
- package/dist/safe-bash-query-engine/interpreter.js +10 -10
- package/dist/safe-bash-query-engine/query-core.js +12 -12
- package/dist/safe-bash-query-engine/regex.js +3 -3
- package/dist/safe-bash-query-engine/splits.js +4 -4
- package/dist/safe-bash-query-engine/values.js +2 -2
- package/package.json +9 -3
- package/dist/safe-bash/opt-in/commands/cmp/compare.js +0 -95
- package/dist/safe-bash/opt-in/commands/cmp/io.js +0 -218
- package/dist/safe-bash/command-chunks/{chunk-FXYWQ6S4.js → chunk-2VTMZTV3.js} +0 -0
- package/dist/safe-bash/command-chunks/{chunk-DEH3CMGL.js → chunk-QJ3ONEBI.js} +3 -3
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// packages/safe-bash-command-pdftotext/dist/index.js
|
|
6
6
|
init_buffer();
|
|
7
|
+
import { yieldTurn, drainCooperativeSteps as drainSteps } from "../safe-bash-contracts/yield.js";
|
|
8
|
+
import { InputByteBudget } from "../safe-bash-contracts/io.js";
|
|
7
9
|
import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
|
|
8
10
|
import {
|
|
9
11
|
commandRuntimeIdentity,
|
|
@@ -44895,7 +44897,7 @@ function renderTsv(pages, args) {
|
|
|
44895
44897
|
}
|
|
44896
44898
|
return rows.join("\n") + "\n";
|
|
44897
44899
|
}
|
|
44898
|
-
function
|
|
44900
|
+
function* extractPdfToTextBytesSteps(bytes, argv = []) {
|
|
44899
44901
|
const args = parseArgs(argv);
|
|
44900
44902
|
const stderrParts = [];
|
|
44901
44903
|
if (args.invalidEolWarning) {
|
|
@@ -44974,12 +44976,14 @@ ${[...SUPPORTED_ENCODINGS].join("\n")}
|
|
|
44974
44976
|
const mode = args.raw ? "raw" : args.layout ? "layout" : "logical";
|
|
44975
44977
|
const pages = [];
|
|
44976
44978
|
for (let p = firstPage; p <= lastPage; p++) {
|
|
44979
|
+
yield;
|
|
44977
44980
|
const page = doc.getPage(p - 1);
|
|
44978
44981
|
let pageCropBoxPt;
|
|
44979
44982
|
if (args.cropbox) {
|
|
44980
44983
|
let cur = page.pageDict;
|
|
44981
44984
|
const visited = /* @__PURE__ */ new Set();
|
|
44982
44985
|
while (cur && !visited.has(cur)) {
|
|
44986
|
+
yield;
|
|
44983
44987
|
visited.add(cur);
|
|
44984
44988
|
const cb = doc.cos.resolveArray(dictGet(cur, "CropBox"));
|
|
44985
44989
|
if (cb && cb.items.length >= 4) {
|
|
@@ -45058,6 +45062,7 @@ ${escapeXml(tsvText)}</pre>
|
|
|
45058
45062
|
const eolChar = args.eol === "dos" ? "\r\n" : args.eol === "mac" ? "\r" : "\n";
|
|
45059
45063
|
let textOut = "";
|
|
45060
45064
|
for (const { pageNumber, extracted } of pages) {
|
|
45065
|
+
yield;
|
|
45061
45066
|
let pageText = formatExtractedPageText(extracted, {
|
|
45062
45067
|
mode,
|
|
45063
45068
|
rejoinHyphens: mode === "logical" && args.removeHyphens,
|
|
@@ -45069,6 +45074,7 @@ ${escapeXml(tsvText)}</pre>
|
|
|
45069
45074
|
const annots = extractPageAnnotations(doc.cos, doc.getPage(pageNumber - 1).pageDict);
|
|
45070
45075
|
const uris = [];
|
|
45071
45076
|
for (const ann of annots) {
|
|
45077
|
+
yield;
|
|
45072
45078
|
if (ann.uri && !pageText.includes(ann.uri) && !uris.includes(ann.uri)) {
|
|
45073
45079
|
uris.push(ann.uri);
|
|
45074
45080
|
}
|
|
@@ -45123,14 +45129,34 @@ ${escapeXml(textOut)}</pre>
|
|
|
45123
45129
|
outputPath: args.outputFile ?? "-"
|
|
45124
45130
|
};
|
|
45125
45131
|
}
|
|
45126
|
-
|
|
45132
|
+
function extractPdfToTextBytes(bytes, argv = []) {
|
|
45133
|
+
const steps = extractPdfToTextBytesSteps(bytes, argv);
|
|
45134
|
+
for (; ; ) {
|
|
45135
|
+
const step = steps.next();
|
|
45136
|
+
if (step.done) return step.value;
|
|
45137
|
+
}
|
|
45138
|
+
}
|
|
45139
|
+
function* extractPdfToTextBytesCooperativelySteps(bytes, argv = [], signal) {
|
|
45140
|
+
const steps = extractPdfToTextBytesSteps(bytes, argv);
|
|
45141
|
+
try {
|
|
45142
|
+
for (; ; ) {
|
|
45143
|
+
yield;
|
|
45144
|
+
const step = steps.next();
|
|
45145
|
+
if (step.done)
|
|
45146
|
+
return step.value;
|
|
45147
|
+
}
|
|
45148
|
+
} finally {
|
|
45149
|
+
steps.return({ exitCode: 1, output: "", stderr: "", outputPath: "-" });
|
|
45150
|
+
}
|
|
45151
|
+
}
|
|
45152
|
+
function* runPdftotextCliSteps(argv, files, stdinBytes = new Uint8Array(0), signal) {
|
|
45127
45153
|
const args = parseArgs(argv);
|
|
45128
45154
|
if (args.error || args.listenc || args.version || args.help) {
|
|
45129
|
-
return
|
|
45155
|
+
return yield* extractPdfToTextBytesCooperativelySteps(new Uint8Array(0), argv, signal);
|
|
45130
45156
|
}
|
|
45131
45157
|
const target = args.inputFile ?? "-";
|
|
45132
45158
|
if (target === "-") {
|
|
45133
|
-
return
|
|
45159
|
+
return yield* extractPdfToTextBytesCooperativelySteps(stdinBytes, argv, signal);
|
|
45134
45160
|
}
|
|
45135
45161
|
const fileBytes = files.get(target);
|
|
45136
45162
|
if (!fileBytes) {
|
|
@@ -45142,9 +45168,13 @@ async function runPdftotextCli(argv, files, stdinBytes = new Uint8Array(0)) {
|
|
|
45142
45168
|
outputPath: args.outputFile ?? "-"
|
|
45143
45169
|
};
|
|
45144
45170
|
}
|
|
45145
|
-
return
|
|
45171
|
+
return yield* extractPdfToTextBytesCooperativelySteps(fileBytes, argv, signal);
|
|
45172
|
+
}
|
|
45173
|
+
async function runPdftotextCli(argv, files, stdinBytes = new Uint8Array(0), signal) {
|
|
45174
|
+
return drainSteps(runPdftotextCliSteps(argv, files, stdinBytes, signal), signal);
|
|
45146
45175
|
}
|
|
45147
45176
|
async function pdftotext(context) {
|
|
45177
|
+
let cooperativeWork = 63;
|
|
45148
45178
|
const invocation = createOutputOperation(context, { write: async () => {
|
|
45149
45179
|
} });
|
|
45150
45180
|
try {
|
|
@@ -45152,7 +45182,7 @@ async function pdftotext(context) {
|
|
|
45152
45182
|
const argv = [...carrier.args];
|
|
45153
45183
|
const parsed = parseArgs(argv);
|
|
45154
45184
|
if (parsed.error || parsed.listenc || parsed.version || parsed.help) {
|
|
45155
|
-
const res2 =
|
|
45185
|
+
const res2 = await drainSteps(extractPdfToTextBytesCooperativelySteps(new Uint8Array(0), argv, invocation.signal), invocation.signal);
|
|
45156
45186
|
if (res2.stderr) {
|
|
45157
45187
|
await writeBytes(context.stderr, new TextEncoder().encode(res2.stderr), invocation.signal);
|
|
45158
45188
|
}
|
|
@@ -45175,6 +45205,7 @@ async function pdftotext(context) {
|
|
|
45175
45205
|
const chunks = [];
|
|
45176
45206
|
let total = 0;
|
|
45177
45207
|
for await (const chunk of readBytes(context.stdin, invocation.signal)) {
|
|
45208
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45178
45209
|
chunks.push(chunk);
|
|
45179
45210
|
total += chunk.byteLength;
|
|
45180
45211
|
chargeBytes(chunk.byteLength);
|
|
@@ -45182,6 +45213,7 @@ async function pdftotext(context) {
|
|
|
45182
45213
|
pdfBytes = new Uint8Array(total);
|
|
45183
45214
|
let offset = 0;
|
|
45184
45215
|
for (const c of chunks) {
|
|
45216
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45185
45217
|
pdfBytes.set(c, offset);
|
|
45186
45218
|
offset += c.byteLength;
|
|
45187
45219
|
}
|
|
@@ -45199,7 +45231,7 @@ async function pdftotext(context) {
|
|
|
45199
45231
|
return { exitCode: 1 };
|
|
45200
45232
|
}
|
|
45201
45233
|
}
|
|
45202
|
-
const res =
|
|
45234
|
+
const res = await drainSteps(extractPdfToTextBytesCooperativelySteps(pdfBytes, argv, invocation.signal), invocation.signal);
|
|
45203
45235
|
if (res.stderr) {
|
|
45204
45236
|
await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
|
|
45205
45237
|
}
|
|
@@ -45229,13 +45261,14 @@ async function pdftotext(context) {
|
|
|
45229
45261
|
await invocation.close();
|
|
45230
45262
|
}
|
|
45231
45263
|
}
|
|
45232
|
-
function createPdftotextCommand(
|
|
45264
|
+
function createPdftotextCommand(options = {}) {
|
|
45265
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
45233
45266
|
return Object.freeze({
|
|
45234
45267
|
name: "pdftotext",
|
|
45235
45268
|
runtimeIdentity: commandRuntimeIdentity,
|
|
45236
45269
|
description: "Extract PDF text, layout, XHTML bounding boxes, and TSV via @poe-code/pdf-ast",
|
|
45237
45270
|
execute(context) {
|
|
45238
|
-
return
|
|
45271
|
+
return new InputByteBudget(maxInputBytes).run(context, pdftotext);
|
|
45239
45272
|
}
|
|
45240
45273
|
});
|
|
45241
45274
|
}
|
|
@@ -45258,10 +45291,8 @@ function bytesToBase64(bytes) {
|
|
|
45258
45291
|
}
|
|
45259
45292
|
return out;
|
|
45260
45293
|
}
|
|
45261
|
-
|
|
45262
|
-
|
|
45263
|
-
}
|
|
45264
|
-
function runPdftohtmlCliSync(argv, files) {
|
|
45294
|
+
function* runPdftohtmlCliSteps(argv, files, signal) {
|
|
45295
|
+
let cooperativeWork = 63;
|
|
45265
45296
|
let xmlMode = false;
|
|
45266
45297
|
let toStdout = false;
|
|
45267
45298
|
let ignoreImages = false;
|
|
@@ -45274,6 +45305,8 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45274
45305
|
let password = "";
|
|
45275
45306
|
const positionals = [];
|
|
45276
45307
|
for (let i = 0; i < argv.length; i++) {
|
|
45308
|
+
if (++cooperativeWork % 64 === 0)
|
|
45309
|
+
yield;
|
|
45277
45310
|
const arg = argv[i];
|
|
45278
45311
|
if (arg === "-v" || arg === "--version") {
|
|
45279
45312
|
return { exitCode: 0, stdout: "pdftohtml version 24.08.0\n", stderr: "" };
|
|
@@ -45343,6 +45376,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45343
45376
|
}
|
|
45344
45377
|
const pageRefToNum = /* @__PURE__ */ new Map();
|
|
45345
45378
|
for (let i = 0; i < doc.pageCount; i++) {
|
|
45379
|
+
yield;
|
|
45346
45380
|
pageRefToNum.set(doc.getPage(i).ref.objectNumber, i + 1);
|
|
45347
45381
|
}
|
|
45348
45382
|
const resolveOutlineDestPage = (itemDict) => {
|
|
@@ -45354,11 +45388,13 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45354
45388
|
let cur = firstNode;
|
|
45355
45389
|
while (cur) {
|
|
45356
45390
|
if (cur.kind === "ref") {
|
|
45357
|
-
if (visited.has(cur.objectNumber))
|
|
45391
|
+
if (visited.has(cur.objectNumber))
|
|
45392
|
+
break;
|
|
45358
45393
|
visited.add(cur.objectNumber);
|
|
45359
45394
|
}
|
|
45360
45395
|
const dict = doc.cos.resolveDict(cur);
|
|
45361
|
-
if (!dict)
|
|
45396
|
+
if (!dict)
|
|
45397
|
+
break;
|
|
45362
45398
|
const tNode = doc.cos.resolve(dictGet(dict, "Title"));
|
|
45363
45399
|
const title = tNode?.kind === "string" ? decodePdfString(tNode) : "";
|
|
45364
45400
|
const pageNumber = resolveOutlineDestPage(dict);
|
|
@@ -45381,6 +45417,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45381
45417
|
`<pdf2xml producer="@poe-code/pdf-ast" version="24.08.0">`
|
|
45382
45418
|
];
|
|
45383
45419
|
for (let p = firstPage; p <= endPage; p++) {
|
|
45420
|
+
yield;
|
|
45384
45421
|
const page = doc.getPage(p - 1);
|
|
45385
45422
|
const { width, height } = page.getSize();
|
|
45386
45423
|
const extracted = page.extractPage();
|
|
@@ -45391,6 +45428,8 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45391
45428
|
const fontSubDict = resDict ? doc.cos.resolveDict(dictGet(resDict, "Font")) : void 0;
|
|
45392
45429
|
if (fontSubDict) {
|
|
45393
45430
|
for (const entry of fontSubDict.entries) {
|
|
45431
|
+
if (++cooperativeWork % 64 === 0)
|
|
45432
|
+
yield;
|
|
45394
45433
|
const fDict = doc.cos.resolveDict(entry.value);
|
|
45395
45434
|
const bfNode = fDict ? doc.cos.resolve(dictGet(fDict, "BaseFont") ?? dictGet(fDict, "Name")) : void 0;
|
|
45396
45435
|
if (bfNode?.kind === "name") {
|
|
@@ -45408,6 +45447,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45408
45447
|
lines.push(` <page number="${p}" position="absolute" top="0" left="0" height="${Math.round(height * zoom)}" width="${Math.round(width * zoom)}">`);
|
|
45409
45448
|
const imageLines = [];
|
|
45410
45449
|
for (let imgIdx = 0; imgIdx < pageImages.length; imgIdx++) {
|
|
45450
|
+
yield;
|
|
45411
45451
|
const img = pageImages[imgIdx];
|
|
45412
45452
|
const imgBytes = imageFmt === "jpg" ? encodeJpeg(img.bitmap) : encodePng(img.bitmap);
|
|
45413
45453
|
const imgFile = `page${p}_${imgIdx + 1}.${imageFmt}`;
|
|
@@ -45420,7 +45460,11 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45420
45460
|
}
|
|
45421
45461
|
const textLines = [];
|
|
45422
45462
|
for (const block of extracted.blocks) {
|
|
45463
|
+
if (++cooperativeWork % 64 === 0)
|
|
45464
|
+
yield;
|
|
45423
45465
|
for (const line of block.lines) {
|
|
45466
|
+
if (++cooperativeWork % 64 === 0)
|
|
45467
|
+
yield;
|
|
45424
45468
|
const [x0, y0, x1, y1] = line.bbox;
|
|
45425
45469
|
const top = Math.max(0, Math.round((height - y1) * zoom));
|
|
45426
45470
|
const left = Math.max(0, Math.round(x0 * zoom));
|
|
@@ -45436,13 +45480,9 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45436
45480
|
if (specId === void 0) {
|
|
45437
45481
|
specId = fontSpecIdByKey.size;
|
|
45438
45482
|
fontSpecIdByKey.set(specKey, specId);
|
|
45439
|
-
fontSpecLines.push(
|
|
45440
|
-
` <fontspec id="${specId}" size="${scaledSize}" family="${escapeHtmlXml(family)}" color="#000000"/>`
|
|
45441
|
-
);
|
|
45483
|
+
fontSpecLines.push(` <fontspec id="${specId}" size="${scaledSize}" family="${escapeHtmlXml(family)}" color="#000000"/>`);
|
|
45442
45484
|
}
|
|
45443
|
-
const matchingLink = annots.find(
|
|
45444
|
-
(a) => a.uri && Math.min(x1, Math.max(a.rect[0], a.rect[2])) > Math.max(x0, Math.min(a.rect[0], a.rect[2])) && Math.min(y1, Math.max(a.rect[1], a.rect[3])) > Math.max(y0, Math.min(a.rect[1], a.rect[3]))
|
|
45445
|
-
);
|
|
45485
|
+
const matchingLink = annots.find((a) => a.uri && Math.min(x1, Math.max(a.rect[0], a.rect[2])) > Math.max(x0, Math.min(a.rect[0], a.rect[2])) && Math.min(y1, Math.max(a.rect[1], a.rect[3])) > Math.max(y0, Math.min(a.rect[1], a.rect[3])));
|
|
45446
45486
|
let styledText = escapeHtmlXml(line.text);
|
|
45447
45487
|
const lowerFam = family.toLowerCase();
|
|
45448
45488
|
if (lowerFam.includes("italic") || lowerFam.includes("oblique")) {
|
|
@@ -45483,6 +45523,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45483
45523
|
`<body>`
|
|
45484
45524
|
];
|
|
45485
45525
|
for (let p = firstPage; p <= endPage; p++) {
|
|
45526
|
+
yield;
|
|
45486
45527
|
const page = doc.getPage(p - 1);
|
|
45487
45528
|
const { width, height } = page.getSize();
|
|
45488
45529
|
const extracted = page.extractPage();
|
|
@@ -45490,6 +45531,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45490
45531
|
const pageImages = ignoreImages ? [] : extractDocumentImages(doc.cos, { firstPage: p, lastPage: p });
|
|
45491
45532
|
lines.push(`<div class="page" id="page${p}" style="position:relative;width:${Math.round(width * zoom)}pt;height:${Math.round(height * zoom)}pt;">`);
|
|
45492
45533
|
for (let imgIdx = 0; imgIdx < pageImages.length; imgIdx++) {
|
|
45534
|
+
yield;
|
|
45493
45535
|
const img = pageImages[imgIdx];
|
|
45494
45536
|
const imgBytes = imageFmt === "jpg" ? encodeJpeg(img.bitmap) : encodePng(img.bitmap);
|
|
45495
45537
|
const imgFile = `page${p}_${imgIdx + 1}.${imageFmt}`;
|
|
@@ -45501,13 +45543,15 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45501
45543
|
lines.push(` <img src="${src}" width="${img.width}" height="${img.height}"/>`);
|
|
45502
45544
|
}
|
|
45503
45545
|
for (const block of extracted.blocks) {
|
|
45546
|
+
if (++cooperativeWork % 64 === 0)
|
|
45547
|
+
yield;
|
|
45504
45548
|
for (const line of block.lines) {
|
|
45549
|
+
if (++cooperativeWork % 64 === 0)
|
|
45550
|
+
yield;
|
|
45505
45551
|
const [x0, y0, x1, y1] = line.bbox;
|
|
45506
45552
|
const top = Math.max(0, Math.round((height - y1) * zoom));
|
|
45507
45553
|
const left = Math.max(0, Math.round(x0 * zoom));
|
|
45508
|
-
const matchingLink = annots.find(
|
|
45509
|
-
(a) => a.uri && Math.min(x1, Math.max(a.rect[0], a.rect[2])) > Math.max(x0, Math.min(a.rect[0], a.rect[2])) && Math.min(y1, Math.max(a.rect[1], a.rect[3])) > Math.max(y0, Math.min(a.rect[1], a.rect[3]))
|
|
45510
|
-
);
|
|
45554
|
+
const matchingLink = annots.find((a) => a.uri && Math.min(x1, Math.max(a.rect[0], a.rect[2])) > Math.max(x0, Math.min(a.rect[0], a.rect[2])) && Math.min(y1, Math.max(a.rect[1], a.rect[3])) > Math.max(y0, Math.min(a.rect[1], a.rect[3])));
|
|
45511
45555
|
const firstWord = line.words[0];
|
|
45512
45556
|
const rawFontName = firstWord?.fontName ?? firstWord?.glyphs[0]?.fontName ?? "Helvetica";
|
|
45513
45557
|
const cleanFontKey = rawFontName.startsWith("/") ? rawFontName.slice(1) : rawFontName;
|
|
@@ -45559,7 +45603,19 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45559
45603
|
files.set(outPath, new TextEncoder().encode(outputText));
|
|
45560
45604
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
45561
45605
|
}
|
|
45606
|
+
async function runPdftohtmlCli(argv, files, signal) {
|
|
45607
|
+
return drainSteps(runPdftohtmlCliSteps(argv, files, signal), signal);
|
|
45608
|
+
}
|
|
45609
|
+
function runPdftohtmlCliSync(argv, files, signal) {
|
|
45610
|
+
const steps = runPdftohtmlCliSteps(argv, files, signal);
|
|
45611
|
+
let next = steps.next();
|
|
45612
|
+
while (!next.done) {
|
|
45613
|
+
next = steps.next();
|
|
45614
|
+
}
|
|
45615
|
+
return next.value;
|
|
45616
|
+
}
|
|
45562
45617
|
async function pdftohtml(context) {
|
|
45618
|
+
let cooperativeWork = 63;
|
|
45563
45619
|
const invocation = createOutputOperation(context, { write: async () => {
|
|
45564
45620
|
} });
|
|
45565
45621
|
try {
|
|
@@ -45576,6 +45632,7 @@ async function pdftohtml(context) {
|
|
|
45576
45632
|
};
|
|
45577
45633
|
let inputOperand;
|
|
45578
45634
|
for (let i = 0; i < argv.length; i++) {
|
|
45635
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45579
45636
|
const arg = argv[i];
|
|
45580
45637
|
if (["-f", "-l", "-zoom", "-fmt", "-enc", "-upw", "-opw"].includes(arg)) {
|
|
45581
45638
|
i++;
|
|
@@ -45588,6 +45645,7 @@ async function pdftohtml(context) {
|
|
|
45588
45645
|
const chunks = [];
|
|
45589
45646
|
let total = 0;
|
|
45590
45647
|
for await (const chunk of readBytes(context.stdin, invocation.signal)) {
|
|
45648
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45591
45649
|
chunks.push(chunk);
|
|
45592
45650
|
total += chunk.byteLength;
|
|
45593
45651
|
chargeBytes(chunk.byteLength);
|
|
@@ -45596,6 +45654,7 @@ async function pdftohtml(context) {
|
|
|
45596
45654
|
const buf = new Uint8Array(total);
|
|
45597
45655
|
let off = 0;
|
|
45598
45656
|
for (const c of chunks) {
|
|
45657
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45599
45658
|
buf.set(c, off);
|
|
45600
45659
|
off += c.byteLength;
|
|
45601
45660
|
}
|
|
@@ -45603,6 +45662,7 @@ async function pdftohtml(context) {
|
|
|
45603
45662
|
}
|
|
45604
45663
|
}
|
|
45605
45664
|
for (const token of argv) {
|
|
45665
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45606
45666
|
if (token.startsWith("-") && token !== "-") continue;
|
|
45607
45667
|
try {
|
|
45608
45668
|
const bytes = await context.fs.readFile(resolveVfsPath(token), { signal: invocation.signal });
|
|
@@ -45611,8 +45671,9 @@ async function pdftohtml(context) {
|
|
|
45611
45671
|
} catch {
|
|
45612
45672
|
}
|
|
45613
45673
|
}
|
|
45674
|
+
context.inputBudget?.check(0);
|
|
45614
45675
|
const existingSnap = new Map(vfsFiles);
|
|
45615
|
-
const res = await runPdftohtmlCli(argv, vfsFiles);
|
|
45676
|
+
const res = await runPdftohtmlCli(argv, vfsFiles, invocation.signal);
|
|
45616
45677
|
if (res.stderr) {
|
|
45617
45678
|
await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
|
|
45618
45679
|
}
|
|
@@ -45623,6 +45684,7 @@ async function pdftohtml(context) {
|
|
|
45623
45684
|
await writeBytes(stdout.output, outBytes, invocation.signal);
|
|
45624
45685
|
}
|
|
45625
45686
|
for (const [key, val] of vfsFiles.entries()) {
|
|
45687
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45626
45688
|
if (existingSnap.get(key) !== val) {
|
|
45627
45689
|
chargeBytes(val.byteLength);
|
|
45628
45690
|
const abs = resolveVfsPath(key);
|
|
@@ -45634,13 +45696,14 @@ async function pdftohtml(context) {
|
|
|
45634
45696
|
await invocation.close();
|
|
45635
45697
|
}
|
|
45636
45698
|
}
|
|
45637
|
-
function createPdftohtmlCommand(
|
|
45699
|
+
function createPdftohtmlCommand(options = {}) {
|
|
45700
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
45638
45701
|
return Object.freeze({
|
|
45639
45702
|
name: "pdftohtml",
|
|
45640
45703
|
runtimeIdentity: commandRuntimeIdentity,
|
|
45641
45704
|
description: "Convert PDF pages into HTML or XML layout documents via @poe-code/pdf-ast",
|
|
45642
45705
|
execute(context) {
|
|
45643
|
-
return
|
|
45706
|
+
return new InputByteBudget(maxInputBytes).run(context, pdftohtml);
|
|
45644
45707
|
}
|
|
45645
45708
|
});
|
|
45646
45709
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Poe Platform
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type CommandDefinition, type VirtualShellPlugin } from "../safe-bash-contracts/index.js";
|
|
2
|
+
export interface PptxCommandEngine {
|
|
3
|
+
execute(request: {
|
|
4
|
+
readonly args: readonly Uint8Array[];
|
|
5
|
+
readonly signal: AbortSignal;
|
|
6
|
+
readonly readInput: (path: string, maxBytes: number) => Promise<Uint8Array>;
|
|
7
|
+
readonly publishOutput?: (publication: {
|
|
8
|
+
readonly inputPath?: string;
|
|
9
|
+
readonly protectedInputPaths?: readonly string[];
|
|
10
|
+
readonly outputPath: string;
|
|
11
|
+
readonly bytes: Uint8Array;
|
|
12
|
+
readonly originalBytes: Uint8Array;
|
|
13
|
+
readonly inPlace: boolean;
|
|
14
|
+
readonly force: boolean;
|
|
15
|
+
readonly dryRun: boolean;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
readonly exitCode: number;
|
|
19
|
+
readonly stdout: Uint8Array;
|
|
20
|
+
readonly stderr: Uint8Array;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
export interface PptxLimits {
|
|
24
|
+
readonly maxArgumentBytes: number;
|
|
25
|
+
}
|
|
26
|
+
export interface PptxCommandsOptions {
|
|
27
|
+
readonly engine: PptxCommandEngine;
|
|
28
|
+
readonly replace?: boolean;
|
|
29
|
+
readonly limits?: Partial<PptxLimits>;
|
|
30
|
+
}
|
|
31
|
+
export declare function createPptxCommand(options: PptxCommandsOptions): CommandDefinition;
|
|
32
|
+
export declare function createPptxCommands(options: PptxCommandsOptions): readonly CommandDefinition[];
|
|
33
|
+
export declare function pptxCommands(options: PptxCommandsOptions): VirtualShellPlugin;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_buffer
|
|
3
|
+
} from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
|
|
4
|
+
|
|
5
|
+
// packages/safe-bash-command-pptx/dist/index.js
|
|
6
|
+
init_buffer();
|
|
7
|
+
import { shellValueByteLength } from "../safe-bash-contracts/value.js";
|
|
8
|
+
import { collectBytes, FsError, getCommandArguments, writeBytes } from "../safe-bash-contracts/index.js";
|
|
9
|
+
import { writeFileOutput } from "../safe-bash-contracts/filesystem-output.js";
|
|
10
|
+
import { compareObservedEntries } from "../safe-bash-contracts/filesystem-identity.js";
|
|
11
|
+
import { pathOf } from "../safe-bash-io-engine/internal.js";
|
|
12
|
+
import { inputRequirements } from "../safe-bash-io-engine/portable-requirements.js";
|
|
13
|
+
function createPptxCommand(options) {
|
|
14
|
+
if (!options?.engine || typeof options.engine.execute !== "function")
|
|
15
|
+
throw new TypeError("An explicit pptx command engine is required.");
|
|
16
|
+
if (options.replace !== void 0 && typeof options.replace !== "boolean")
|
|
17
|
+
throw new TypeError("pptx replace must be boolean");
|
|
18
|
+
const maxArgumentBytes = options.limits?.maxArgumentBytes ?? Infinity;
|
|
19
|
+
if (maxArgumentBytes !== Infinity && (!Number.isSafeInteger(maxArgumentBytes) || maxArgumentBytes < 0)) {
|
|
20
|
+
throw new RangeError("maxArgumentBytes must be a nonnegative safe integer or Infinity");
|
|
21
|
+
}
|
|
22
|
+
const engine = options.engine;
|
|
23
|
+
return { name: "pptx", filesystemRequirements: inputRequirements, async execute(context) {
|
|
24
|
+
const arguments_ = getCommandArguments(context);
|
|
25
|
+
let argumentBytes = 0;
|
|
26
|
+
for (let index = 0; index < arguments_.args.length; index++) {
|
|
27
|
+
const bytes = shellValueByteLength(arguments_.values[index]);
|
|
28
|
+
if (bytes > maxArgumentBytes - argumentBytes)
|
|
29
|
+
throw new FsError("EFBIG", { message: "document argument limit exceeded" });
|
|
30
|
+
argumentBytes += bytes;
|
|
31
|
+
}
|
|
32
|
+
const snapshots = /* @__PURE__ */ new Map();
|
|
33
|
+
const result = await engine.execute({
|
|
34
|
+
args: arguments_.args.map((_, index) => arguments_.bytes(index)),
|
|
35
|
+
signal: context.signal,
|
|
36
|
+
async readInput(path, maxBytes) {
|
|
37
|
+
try {
|
|
38
|
+
context.signal.throwIfAborted();
|
|
39
|
+
if (path === "-")
|
|
40
|
+
return await collectBytes(context.stdin, { maxBytes, signal: context.signal });
|
|
41
|
+
const resolved = pathOf(context, path);
|
|
42
|
+
if (!snapshots.has(resolved)) {
|
|
43
|
+
try {
|
|
44
|
+
snapshots.set(resolved, await context.fs.lstat(resolved, { signal: context.signal }));
|
|
45
|
+
} catch {
|
|
46
|
+
context.signal.throwIfAborted();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const capabilities = await context.fs.capabilitiesFor?.(resolved, { signal: context.signal }) ?? context.fs.capabilities;
|
|
50
|
+
context.signal.throwIfAborted();
|
|
51
|
+
if (context.fs.readStream && capabilities.streamingRead !== false) {
|
|
52
|
+
let emitted = false;
|
|
53
|
+
try {
|
|
54
|
+
const stream = context.fs.readStream(resolved, { signal: context.signal });
|
|
55
|
+
return await collectBytes((async function* () {
|
|
56
|
+
for await (const chunk of stream) {
|
|
57
|
+
if (chunk.byteLength)
|
|
58
|
+
emitted = true;
|
|
59
|
+
yield chunk;
|
|
60
|
+
}
|
|
61
|
+
})(), { maxBytes, signal: context.signal });
|
|
62
|
+
} catch (error) {
|
|
63
|
+
context.signal.throwIfAborted();
|
|
64
|
+
if (emitted || !(error instanceof FsError) || error.code !== "ENOTSUP")
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (capabilities.read === false)
|
|
69
|
+
throw new FsError("ENOTSUP");
|
|
70
|
+
const bytes = await context.fs.readFile(resolved, { maxBytes, signal: context.signal });
|
|
71
|
+
context.signal.throwIfAborted();
|
|
72
|
+
if (bytes.byteLength > maxBytes)
|
|
73
|
+
throw new FsError("EFBIG");
|
|
74
|
+
return bytes;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
context.signal.throwIfAborted();
|
|
77
|
+
throw Object.assign(new Error("Input could not be read."), { code: error instanceof FsError && error.code === "EFBIG" ? "resource-limit" : "io-failure" });
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
async publishOutput(publication) {
|
|
81
|
+
try {
|
|
82
|
+
const { fs, signal } = context;
|
|
83
|
+
signal.throwIfAborted();
|
|
84
|
+
const input = publication.inputPath === void 0 || publication.inputPath === "-" ? void 0 : pathOf(context, publication.inputPath);
|
|
85
|
+
const output = pathOf(context, publication.outputPath);
|
|
86
|
+
if (publication.inPlace ? !input || input !== output : input === output)
|
|
87
|
+
throw new FsError("EINVAL");
|
|
88
|
+
const capabilities = await fs.capabilitiesFor?.(output, { signal }) ?? fs.capabilities;
|
|
89
|
+
signal.throwIfAborted();
|
|
90
|
+
if (capabilities.readOnly === true || capabilities.write === false || !capabilities.atomicFileMutation || !fs.writeFileConditional)
|
|
91
|
+
throw new FsError("ENOTSUP");
|
|
92
|
+
let destination;
|
|
93
|
+
try {
|
|
94
|
+
destination = await fs.lstat(output, { signal });
|
|
95
|
+
} catch (error) {
|
|
96
|
+
signal.throwIfAborted();
|
|
97
|
+
if (!(error instanceof FsError) || error.code !== "ENOENT")
|
|
98
|
+
throw error;
|
|
99
|
+
destination = null;
|
|
100
|
+
}
|
|
101
|
+
if (destination && destination.type !== "file")
|
|
102
|
+
throw new FsError("EINVAL");
|
|
103
|
+
if (destination) {
|
|
104
|
+
const protectedInputs = new Set((publication.protectedInputPaths ?? []).filter((path) => path !== "-").map((path) => pathOf(context, path)));
|
|
105
|
+
for (const [source, observed] of snapshots) {
|
|
106
|
+
if (source === input && !protectedInputs.has(source))
|
|
107
|
+
continue;
|
|
108
|
+
const identity = observed.type === "symlink" ? await fs.stat(source, { signal }) : observed;
|
|
109
|
+
if (source === output || await compareObservedEntries(fs, source, identity, fs, output, destination, { signal }) !== "distinct")
|
|
110
|
+
throw new FsError("EINVAL");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (destination && !publication.inPlace) {
|
|
114
|
+
if (!publication.force)
|
|
115
|
+
throw new FsError("EEXIST");
|
|
116
|
+
if (input && await compareObservedEntries(fs, input, await fs.stat(input, { signal }), fs, output, destination, { signal }) !== "distinct")
|
|
117
|
+
throw new FsError("EINVAL");
|
|
118
|
+
}
|
|
119
|
+
const parentPath = output.slice(0, output.lastIndexOf("/")) || "/";
|
|
120
|
+
const parent = await fs.stat(parentPath, { signal });
|
|
121
|
+
if (parent.type !== "directory")
|
|
122
|
+
throw new FsError("ENOTDIR");
|
|
123
|
+
if (publication.inPlace) {
|
|
124
|
+
const original = snapshots.get(input);
|
|
125
|
+
if (!original || original.type !== "file" || !destination || original.revision === void 0 || original.revision !== destination.revision || original.size !== destination.size || original.mode !== destination.mode || original.nlink !== destination.nlink || original.mtimeMs !== destination.mtimeMs || original.ctimeMs !== destination.ctimeMs || await compareObservedEntries(fs, input, original, fs, output, destination, { signal }) !== "same")
|
|
126
|
+
throw new FsError("EAGAIN");
|
|
127
|
+
const current = await fs.readFile(input, { maxBytes: publication.originalBytes.length, signal });
|
|
128
|
+
if (current.length !== publication.originalBytes.length || current.some((byte, index) => byte !== publication.originalBytes[index]))
|
|
129
|
+
throw new FsError("EAGAIN");
|
|
130
|
+
destination = original;
|
|
131
|
+
}
|
|
132
|
+
signal.throwIfAborted();
|
|
133
|
+
if (!publication.dryRun)
|
|
134
|
+
await writeFileOutput(context, publication.bytes, async (bytes) => {
|
|
135
|
+
await fs.writeFileConditional(output, bytes, { parent, expected: destination, signal });
|
|
136
|
+
});
|
|
137
|
+
} catch (error) {
|
|
138
|
+
context.signal.throwIfAborted();
|
|
139
|
+
const code = error instanceof FsError && error.code === "EAGAIN" ? "stale-input" : error instanceof FsError && error.code === "ENOTSUP" ? "publication-unsupported" : "io-failure";
|
|
140
|
+
throw Object.assign(new Error("Output could not be published."), { code });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
if (result.stdout.length)
|
|
145
|
+
await writeBytes(context.stdout, result.stdout, context.signal);
|
|
146
|
+
if (result.stderr.length)
|
|
147
|
+
await writeBytes(context.stderr, result.stderr, context.signal);
|
|
148
|
+
return { exitCode: result.exitCode };
|
|
149
|
+
} };
|
|
150
|
+
}
|
|
151
|
+
function createPptxCommands(options) {
|
|
152
|
+
return [createPptxCommand(options)];
|
|
153
|
+
}
|
|
154
|
+
function pptxCommands(options) {
|
|
155
|
+
const commands = createPptxCommands(options);
|
|
156
|
+
const replace = options.replace ?? false;
|
|
157
|
+
return { name: "pptx-commands", setup(host) {
|
|
158
|
+
if (!replace && host.commands.has("pptx"))
|
|
159
|
+
throw new Error("Command already registered: pptx");
|
|
160
|
+
for (const command of commands)
|
|
161
|
+
host.commands.register(command, { replace });
|
|
162
|
+
} };
|
|
163
|
+
}
|
|
164
|
+
export {
|
|
165
|
+
createPptxCommand,
|
|
166
|
+
createPptxCommands,
|
|
167
|
+
pptxCommands
|
|
168
|
+
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { type CommandContext, type CommandDefinition } from "../safe-bash-contracts/command.js";
|
|
2
2
|
import type { VirtualShellPlugin } from "../safe-bash-contracts/plugin.js";
|
|
3
|
+
export interface QpdfLimits {
|
|
4
|
+
readonly maxInputBytes: number;
|
|
5
|
+
readonly maxOutputBytes: number;
|
|
6
|
+
readonly maxArgumentBytes: number;
|
|
7
|
+
}
|
|
3
8
|
export interface QpdfCommandOptions {
|
|
9
|
+
readonly limits?: Partial<QpdfLimits>;
|
|
4
10
|
readonly replace?: boolean;
|
|
5
11
|
}
|
|
6
12
|
export interface QpdfCliResult {
|
|
@@ -9,12 +15,12 @@ export interface QpdfCliResult {
|
|
|
9
15
|
readonly stderr: string;
|
|
10
16
|
}
|
|
11
17
|
export declare function parseQpdfPageRange(rangeSpec: string, totalPages: number): number[];
|
|
12
|
-
export declare function runQpdfCli(argv: readonly string[], files: Map<string, Uint8Array>, readStdin?: () => Promise<void
|
|
18
|
+
export declare function runQpdfCli(argv: readonly string[], files: Map<string, Uint8Array>, readStdin?: () => Promise<void>, signal?: AbortSignal): Promise<QpdfCliResult>;
|
|
13
19
|
export declare function runQpdfCliSync(argv: readonly string[], files: Map<string, Uint8Array>): QpdfCliResult;
|
|
14
|
-
export declare function qpdf(context: CommandContext): Promise<{
|
|
20
|
+
export declare function qpdf(context: CommandContext, options?: QpdfCommandOptions): Promise<{
|
|
15
21
|
exitCode: number;
|
|
16
22
|
}>;
|
|
17
|
-
export declare function createQpdfCommand(
|
|
23
|
+
export declare function createQpdfCommand(options?: QpdfCommandOptions): CommandDefinition;
|
|
18
24
|
export declare const qpdfCommand: CommandDefinition;
|
|
19
25
|
export declare function qpdfCommands(options?: QpdfCommandsOptions): VirtualShellPlugin;
|
|
20
26
|
export type QpdfCommandsOptions = QpdfCommandOptions;
|