@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-pdfinfo/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,
|
|
@@ -45687,7 +45689,7 @@ function applyPopplerOutputEncoding(text, encoding) {
|
|
|
45687
45689
|
}
|
|
45688
45690
|
return text;
|
|
45689
45691
|
}
|
|
45690
|
-
function
|
|
45692
|
+
function* inspectPdfBytesSteps(bytes, argv = [], options = {}) {
|
|
45691
45693
|
const args = parseArgs(argv);
|
|
45692
45694
|
if (args.error) {
|
|
45693
45695
|
return { exitCode: args.errorExitCode ?? 99, stdout: "", stderr: args.error };
|
|
@@ -45760,6 +45762,7 @@ ${[...SUPPORTED_ENCODINGS].join("\n")}
|
|
|
45760
45762
|
const actions = collectJavaScriptActions(cos);
|
|
45761
45763
|
let out2 = "";
|
|
45762
45764
|
for (const act of actions) {
|
|
45765
|
+
yield;
|
|
45763
45766
|
out2 += `Name: ${act.name}
|
|
45764
45767
|
JS:
|
|
45765
45768
|
${act.js}
|
|
@@ -45791,6 +45794,7 @@ ${act.js}
|
|
|
45791
45794
|
const customKeys = [];
|
|
45792
45795
|
if (info3) {
|
|
45793
45796
|
for (const entry of info3.entries) {
|
|
45797
|
+
yield;
|
|
45794
45798
|
const key = entry.key.decoded;
|
|
45795
45799
|
const resolved = cos.resolve(entry.value);
|
|
45796
45800
|
if (resolved?.kind === "string") {
|
|
@@ -45805,15 +45809,18 @@ ${act.js}
|
|
|
45805
45809
|
customKeys.sort((a, b) => a.localeCompare(b));
|
|
45806
45810
|
let out = "";
|
|
45807
45811
|
for (const key of ["Title", "Subject", "Keywords", "Author", "Creator", "Producer"]) {
|
|
45812
|
+
yield;
|
|
45808
45813
|
const val = infoMap.get(key);
|
|
45809
45814
|
if (val !== void 0) out += formatField(key, val);
|
|
45810
45815
|
}
|
|
45811
45816
|
for (const dateKey of ["CreationDate", "ModDate"]) {
|
|
45817
|
+
yield;
|
|
45812
45818
|
const val = infoMap.get(dateKey);
|
|
45813
45819
|
if (val !== void 0) out += formatField(dateKey, formatPdfDate(val, dateMode));
|
|
45814
45820
|
}
|
|
45815
45821
|
if (args.custom) {
|
|
45816
45822
|
for (const customKey of customKeys) {
|
|
45823
|
+
yield;
|
|
45817
45824
|
const val = infoMap.get(customKey);
|
|
45818
45825
|
if (val !== void 0) out += formatField(customKey, val);
|
|
45819
45826
|
}
|
|
@@ -45855,6 +45862,7 @@ ${act.js}
|
|
|
45855
45862
|
out += formatField("Encrypted", "no");
|
|
45856
45863
|
}
|
|
45857
45864
|
for (let p = firstPage; p <= lastPage; p++) {
|
|
45865
|
+
yield;
|
|
45858
45866
|
const page = doc.getPage(p - 1);
|
|
45859
45867
|
const mediaBox = resolvePageBox(cos, page, "MediaBox", [0, 0, 612, 792]);
|
|
45860
45868
|
const cropBox = resolvePageBox(cos, page, "CropBox", mediaBox);
|
|
@@ -45885,17 +45893,37 @@ ${act.js}
|
|
|
45885
45893
|
out += formatField("PDF version", cos.version);
|
|
45886
45894
|
return { exitCode: 0, stdout: applyPopplerOutputEncoding(out, args.encoding), stderr: "" };
|
|
45887
45895
|
}
|
|
45888
|
-
|
|
45896
|
+
function inspectPdfBytes(bytes, argv = [], options = {}) {
|
|
45897
|
+
const steps = inspectPdfBytesSteps(bytes, argv, options);
|
|
45898
|
+
for (; ; ) {
|
|
45899
|
+
const step = steps.next();
|
|
45900
|
+
if (step.done) return step.value;
|
|
45901
|
+
}
|
|
45902
|
+
}
|
|
45903
|
+
function* inspectPdfBytesCooperativelySteps(bytes, argv = [], options = {}, signal) {
|
|
45904
|
+
const steps = inspectPdfBytesSteps(bytes, argv, options);
|
|
45905
|
+
try {
|
|
45906
|
+
for (; ; ) {
|
|
45907
|
+
yield;
|
|
45908
|
+
const step = steps.next();
|
|
45909
|
+
if (step.done)
|
|
45910
|
+
return step.value;
|
|
45911
|
+
}
|
|
45912
|
+
} finally {
|
|
45913
|
+
steps.return({ exitCode: 1, stdout: "", stderr: "" });
|
|
45914
|
+
}
|
|
45915
|
+
}
|
|
45916
|
+
function* runPdfinfoCliSteps(argv, files, stdinBytes = new Uint8Array(0), signal) {
|
|
45889
45917
|
const args = parseArgs(argv);
|
|
45890
45918
|
if (args.error) {
|
|
45891
45919
|
return { exitCode: args.errorExitCode ?? 99, stdout: "", stderr: args.error };
|
|
45892
45920
|
}
|
|
45893
45921
|
if (args.listenc || args.version || args.help) {
|
|
45894
|
-
return
|
|
45922
|
+
return yield* inspectPdfBytesCooperativelySteps(new Uint8Array(0), argv, void 0, signal);
|
|
45895
45923
|
}
|
|
45896
45924
|
const target = args.inputFile ?? "-";
|
|
45897
45925
|
if (target === "-") {
|
|
45898
|
-
return
|
|
45926
|
+
return yield* inspectPdfBytesCooperativelySteps(stdinBytes, argv, { isStdin: true, fileSize: 0 }, signal);
|
|
45899
45927
|
}
|
|
45900
45928
|
const fileBytes = files.get(target);
|
|
45901
45929
|
if (!fileBytes) {
|
|
@@ -45906,9 +45934,13 @@ async function runPdfinfoCli(argv, files, stdinBytes = new Uint8Array(0)) {
|
|
|
45906
45934
|
`
|
|
45907
45935
|
};
|
|
45908
45936
|
}
|
|
45909
|
-
return
|
|
45937
|
+
return yield* inspectPdfBytesCooperativelySteps(fileBytes, argv, { fileSize: fileBytes.byteLength }, signal);
|
|
45938
|
+
}
|
|
45939
|
+
async function runPdfinfoCli(argv, files, stdinBytes = new Uint8Array(0), signal) {
|
|
45940
|
+
return drainSteps(runPdfinfoCliSteps(argv, files, stdinBytes, signal), signal);
|
|
45910
45941
|
}
|
|
45911
45942
|
async function pdfinfo(context) {
|
|
45943
|
+
let cooperativeWork = 63;
|
|
45912
45944
|
const invocation = createOutputOperation(context, { write: async () => {
|
|
45913
45945
|
} });
|
|
45914
45946
|
try {
|
|
@@ -45924,7 +45956,7 @@ async function pdfinfo(context) {
|
|
|
45924
45956
|
return { exitCode: parsed.errorExitCode ?? 99 };
|
|
45925
45957
|
}
|
|
45926
45958
|
if (parsed.listenc || parsed.version || parsed.help) {
|
|
45927
|
-
const res2 =
|
|
45959
|
+
const res2 = await drainSteps(inspectPdfBytesCooperativelySteps(new Uint8Array(0), argv, void 0, invocation.signal), invocation.signal);
|
|
45928
45960
|
if (res2.stdout) {
|
|
45929
45961
|
const stdout = invocation.child(context.stdout);
|
|
45930
45962
|
await writeBytes(stdout.output, new TextEncoder().encode(res2.stdout), invocation.signal);
|
|
@@ -45946,6 +45978,7 @@ async function pdfinfo(context) {
|
|
|
45946
45978
|
const chunks = [];
|
|
45947
45979
|
let total = 0;
|
|
45948
45980
|
for await (const chunk of readBytes(context.stdin, invocation.signal)) {
|
|
45981
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45949
45982
|
chunks.push(chunk);
|
|
45950
45983
|
total += chunk.byteLength;
|
|
45951
45984
|
chargeBytes(chunk.byteLength);
|
|
@@ -45953,6 +45986,7 @@ async function pdfinfo(context) {
|
|
|
45953
45986
|
pdfBytes = new Uint8Array(total);
|
|
45954
45987
|
let offset = 0;
|
|
45955
45988
|
for (const c of chunks) {
|
|
45989
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45956
45990
|
pdfBytes.set(c, offset);
|
|
45957
45991
|
offset += c.byteLength;
|
|
45958
45992
|
}
|
|
@@ -45968,10 +46002,10 @@ async function pdfinfo(context) {
|
|
|
45968
46002
|
return { exitCode: 1 };
|
|
45969
46003
|
}
|
|
45970
46004
|
}
|
|
45971
|
-
const res =
|
|
46005
|
+
const res = await drainSteps(inspectPdfBytesCooperativelySteps(pdfBytes, argv, {
|
|
45972
46006
|
fileSize: isStdin ? 0 : pdfBytes.byteLength,
|
|
45973
46007
|
isStdin
|
|
45974
|
-
});
|
|
46008
|
+
}, invocation.signal), invocation.signal);
|
|
45975
46009
|
if (res.stderr) {
|
|
45976
46010
|
await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
|
|
45977
46011
|
}
|
|
@@ -45984,18 +46018,20 @@ async function pdfinfo(context) {
|
|
|
45984
46018
|
await invocation.close();
|
|
45985
46019
|
}
|
|
45986
46020
|
}
|
|
45987
|
-
function createPdfinfoCommand(
|
|
46021
|
+
function createPdfinfoCommand(options = {}) {
|
|
46022
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
45988
46023
|
return Object.freeze({
|
|
45989
46024
|
name: "pdfinfo",
|
|
45990
46025
|
runtimeIdentity: commandRuntimeIdentity,
|
|
45991
46026
|
description: "Extract PDF metadata, page boxes, encryption, and structure via @poe-code/pdf-ast",
|
|
45992
46027
|
execute(context) {
|
|
45993
|
-
return
|
|
46028
|
+
return new InputByteBudget(maxInputBytes).run(context, pdfinfo);
|
|
45994
46029
|
}
|
|
45995
46030
|
});
|
|
45996
46031
|
}
|
|
45997
46032
|
var pdfinfoCommand = createPdfinfoCommand();
|
|
45998
|
-
|
|
46033
|
+
function* runPdftoppmCliSteps(argv, files, signal) {
|
|
46034
|
+
let cooperativeWork = 63;
|
|
45999
46035
|
let format = "ppm";
|
|
46000
46036
|
let colorMode = "color";
|
|
46001
46037
|
let dpi = 150;
|
|
@@ -46026,6 +46062,8 @@ async function runPdftoppmCli(argv, files) {
|
|
|
46026
46062
|
let password = "";
|
|
46027
46063
|
const positionals = [];
|
|
46028
46064
|
for (let i = 0; i < argv.length; i++) {
|
|
46065
|
+
if (++cooperativeWork % 64 === 0)
|
|
46066
|
+
yield;
|
|
46029
46067
|
const arg = argv[i];
|
|
46030
46068
|
if (arg === "-v" || arg === "--version") {
|
|
46031
46069
|
return { exitCode: 0, stdout: "pdftoppm version 24.08.0\n", stderr: "" };
|
|
@@ -46064,6 +46102,8 @@ async function runPdftoppmCli(argv, files) {
|
|
|
46064
46102
|
} else if (arg === "-jpegopt") {
|
|
46065
46103
|
const optStr = argv[++i] ?? "";
|
|
46066
46104
|
for (const part of optStr.split(",")) {
|
|
46105
|
+
if (++cooperativeWork % 64 === 0)
|
|
46106
|
+
yield;
|
|
46067
46107
|
const eqIdx = part.indexOf("=");
|
|
46068
46108
|
if (eqIdx > 0 && part.slice(0, eqIdx).trim().toLowerCase() === "quality") {
|
|
46069
46109
|
const qVal = Number(part.slice(eqIdx + 1).trim());
|
|
@@ -46126,8 +46166,11 @@ async function runPdftoppmCli(argv, files) {
|
|
|
46126
46166
|
const outChunks = [];
|
|
46127
46167
|
const progressLines = [];
|
|
46128
46168
|
for (let p = firstPage; p <= endPage; p++) {
|
|
46129
|
-
|
|
46130
|
-
if (
|
|
46169
|
+
yield;
|
|
46170
|
+
if (oddOnly && p % 2 === 0)
|
|
46171
|
+
continue;
|
|
46172
|
+
if (evenOnly && p % 2 === 1)
|
|
46173
|
+
continue;
|
|
46131
46174
|
const page = doc.getPage(p - 1);
|
|
46132
46175
|
let rawSize = page.getSize();
|
|
46133
46176
|
let resolvedCropBox;
|
|
@@ -46135,6 +46178,8 @@ async function runPdftoppmCli(argv, files) {
|
|
|
46135
46178
|
let cur = page.pageDict;
|
|
46136
46179
|
const visited = /* @__PURE__ */ new Set();
|
|
46137
46180
|
while (cur && !visited.has(cur)) {
|
|
46181
|
+
if (++cooperativeWork % 64 === 0)
|
|
46182
|
+
yield;
|
|
46138
46183
|
visited.add(cur);
|
|
46139
46184
|
const cb = doc.cos.resolveArray(dictGet(cur, "CropBox"));
|
|
46140
46185
|
if (cb && cb.items.length >= 4) {
|
|
@@ -46164,11 +46209,13 @@ async function runPdftoppmCli(argv, files) {
|
|
|
46164
46209
|
} else {
|
|
46165
46210
|
if (scaleToX > 0) {
|
|
46166
46211
|
effDpiX = scaleToX * 72 / ptW;
|
|
46167
|
-
if (scaleToY <= 0)
|
|
46212
|
+
if (scaleToY <= 0)
|
|
46213
|
+
effDpiY = effDpiX;
|
|
46168
46214
|
}
|
|
46169
46215
|
if (scaleToY > 0) {
|
|
46170
46216
|
effDpiY = scaleToY * 72 / ptH;
|
|
46171
|
-
if (scaleToX <= 0)
|
|
46217
|
+
if (scaleToX <= 0)
|
|
46218
|
+
effDpiX = effDpiY;
|
|
46172
46219
|
}
|
|
46173
46220
|
}
|
|
46174
46221
|
let renderedBytes;
|
|
@@ -46211,6 +46258,8 @@ async function runPdftoppmCli(argv, files) {
|
|
|
46211
46258
|
});
|
|
46212
46259
|
if (colorMode !== "color" && (format === "png" || format === "tif" || format === "jpeg")) {
|
|
46213
46260
|
for (let px = 0; px < bitmap.data.length; px += 4) {
|
|
46261
|
+
if (++cooperativeWork % 65536 === 0)
|
|
46262
|
+
yield;
|
|
46214
46263
|
const r = bitmap.data[px];
|
|
46215
46264
|
const g = bitmap.data[px + 1];
|
|
46216
46265
|
const b = bitmap.data[px + 2];
|
|
@@ -46221,27 +46270,33 @@ async function runPdftoppmCli(argv, files) {
|
|
|
46221
46270
|
bitmap.data[px + 2] = v;
|
|
46222
46271
|
}
|
|
46223
46272
|
}
|
|
46224
|
-
if (format === "png")
|
|
46225
|
-
|
|
46226
|
-
else if (format === "
|
|
46227
|
-
|
|
46228
|
-
else if (format === "
|
|
46229
|
-
|
|
46273
|
+
if (format === "png")
|
|
46274
|
+
renderedBytes = encodePng(bitmap);
|
|
46275
|
+
else if (format === "tif")
|
|
46276
|
+
renderedBytes = encodeTiff(bitmap, effDpiX);
|
|
46277
|
+
else if (format === "ppm")
|
|
46278
|
+
renderedBytes = encodePpm(bitmap);
|
|
46279
|
+
else if (format === "pgm")
|
|
46280
|
+
renderedBytes = encodePgm(bitmap);
|
|
46281
|
+
else if (format === "pbm")
|
|
46282
|
+
renderedBytes = encodePbm(bitmap);
|
|
46283
|
+
else
|
|
46284
|
+
renderedBytes = encodeJpeg(bitmap, jpegQuality);
|
|
46230
46285
|
}
|
|
46231
46286
|
if (!prefix || prefix === "-") {
|
|
46232
46287
|
outChunks.push(renderedBytes);
|
|
46233
|
-
if (progress && !quiet)
|
|
46288
|
+
if (progress && !quiet)
|
|
46289
|
+
progressLines.push(`${p} ${endPage} -`);
|
|
46234
46290
|
} else {
|
|
46235
46291
|
const effectivePageNo = setPageNo !== void 0 ? setPageNo + (p - firstPage) : p;
|
|
46236
|
-
const pageNumStr = String(effectivePageNo).padStart(
|
|
46237
|
-
Math.max(padWidth, String(effectivePageNo).length),
|
|
46238
|
-
"0"
|
|
46239
|
-
);
|
|
46292
|
+
const pageNumStr = String(effectivePageNo).padStart(Math.max(padWidth, String(effectivePageNo).length), "0");
|
|
46240
46293
|
const fileName = singleFile && !forceNum ? `${prefix}.${ext}` : `${prefix}${sep}${pageNumStr}.${ext}`;
|
|
46241
46294
|
files.set(fileName, renderedBytes);
|
|
46242
|
-
if (progress && !quiet)
|
|
46295
|
+
if (progress && !quiet)
|
|
46296
|
+
progressLines.push(`${p} ${endPage} ${fileName}`);
|
|
46243
46297
|
}
|
|
46244
|
-
if (singleFile)
|
|
46298
|
+
if (singleFile)
|
|
46299
|
+
break;
|
|
46245
46300
|
}
|
|
46246
46301
|
const stderrText = progressLines.length > 0 ? progressLines.join("\n") + "\n" : "";
|
|
46247
46302
|
if (outChunks.length > 0) {
|
|
@@ -46249,6 +46304,8 @@ async function runPdftoppmCli(argv, files) {
|
|
|
46249
46304
|
const merged = new Uint8Array(totalLen);
|
|
46250
46305
|
let off = 0;
|
|
46251
46306
|
for (const c of outChunks) {
|
|
46307
|
+
if (++cooperativeWork % 64 === 0)
|
|
46308
|
+
yield;
|
|
46252
46309
|
merged.set(c, off);
|
|
46253
46310
|
off += c.byteLength;
|
|
46254
46311
|
}
|
|
@@ -46256,6 +46313,9 @@ async function runPdftoppmCli(argv, files) {
|
|
|
46256
46313
|
}
|
|
46257
46314
|
return { exitCode: 0, stdout: "", stderr: stderrText };
|
|
46258
46315
|
}
|
|
46316
|
+
async function runPdftoppmCli(argv, files, signal) {
|
|
46317
|
+
return drainSteps(runPdftoppmCliSteps(argv, files, signal), signal);
|
|
46318
|
+
}
|
|
46259
46319
|
function formatPopplerSize(byteLength) {
|
|
46260
46320
|
if (byteLength >= 1024 * 1024) {
|
|
46261
46321
|
return `${(byteLength / (1024 * 1024)).toFixed(1)}M`;
|
|
@@ -46271,7 +46331,8 @@ function formatPopplerRatio(byteLength, width, height, components, bpc) {
|
|
|
46271
46331
|
const pct = Math.min(999, Math.max(0.1, byteLength / uncompressedBytes * 100));
|
|
46272
46332
|
return `${pct.toFixed(1)}%`;
|
|
46273
46333
|
}
|
|
46274
|
-
|
|
46334
|
+
function* runPdfimagesCliSteps(argv, files, signal) {
|
|
46335
|
+
let cooperativeWork = 63;
|
|
46275
46336
|
let listOnly = false;
|
|
46276
46337
|
let usePng = false;
|
|
46277
46338
|
let useJpeg = false;
|
|
@@ -46288,6 +46349,8 @@ async function runPdfimagesCli(argv, files) {
|
|
|
46288
46349
|
let password = "";
|
|
46289
46350
|
const positionals = [];
|
|
46290
46351
|
for (let i = 0; i < argv.length; i++) {
|
|
46352
|
+
if (++cooperativeWork % 64 === 0)
|
|
46353
|
+
yield;
|
|
46291
46354
|
const arg = argv[i];
|
|
46292
46355
|
if (arg === "-v" || arg === "--version") {
|
|
46293
46356
|
return { exitCode: 0, stdout: "pdfimages version 24.08.0\n", stderr: "" };
|
|
@@ -46299,23 +46362,34 @@ async function runPdfimagesCli(argv, files) {
|
|
|
46299
46362
|
stderr: ""
|
|
46300
46363
|
};
|
|
46301
46364
|
}
|
|
46302
|
-
if (arg === "-list")
|
|
46303
|
-
|
|
46304
|
-
else if (arg === "-
|
|
46305
|
-
|
|
46306
|
-
else if (arg === "-
|
|
46307
|
-
|
|
46308
|
-
else if (arg === "-
|
|
46365
|
+
if (arg === "-list")
|
|
46366
|
+
listOnly = true;
|
|
46367
|
+
else if (arg === "-png")
|
|
46368
|
+
usePng = true;
|
|
46369
|
+
else if (arg === "-j")
|
|
46370
|
+
useJpeg = true;
|
|
46371
|
+
else if (arg === "-tiff")
|
|
46372
|
+
useTiff = true;
|
|
46373
|
+
else if (arg === "-jp2")
|
|
46374
|
+
useJp2 = true;
|
|
46375
|
+
else if (arg === "-jbig2")
|
|
46376
|
+
useJbig2 = true;
|
|
46377
|
+
else if (arg === "-ccitt")
|
|
46378
|
+
useCcitt = true;
|
|
46309
46379
|
else if (arg === "-all") {
|
|
46310
46380
|
usePng = true;
|
|
46311
46381
|
useJpeg = true;
|
|
46312
46382
|
useJp2 = true;
|
|
46313
46383
|
useJbig2 = true;
|
|
46314
46384
|
useCcitt = true;
|
|
46315
|
-
} else if (arg === "-p")
|
|
46316
|
-
|
|
46317
|
-
else if (arg === "-
|
|
46318
|
-
|
|
46385
|
+
} else if (arg === "-p")
|
|
46386
|
+
includePage = true;
|
|
46387
|
+
else if (arg === "-u")
|
|
46388
|
+
uniqueOnly = true;
|
|
46389
|
+
else if (arg === "-print-filenames")
|
|
46390
|
+
printFilenames = true;
|
|
46391
|
+
else if (arg === "-q")
|
|
46392
|
+
quiet = true;
|
|
46319
46393
|
else if (arg === "-f") {
|
|
46320
46394
|
firstPage = Math.max(1, Number.parseInt(argv[++i] ?? "1", 10) || 1);
|
|
46321
46395
|
} else if (arg === "-l") {
|
|
@@ -46358,9 +46432,11 @@ async function runPdfimagesCli(argv, files) {
|
|
|
46358
46432
|
});
|
|
46359
46433
|
const seenObjectIds = /* @__PURE__ */ new Set();
|
|
46360
46434
|
const extracted = uniqueOnly ? allExtracted.filter((img) => {
|
|
46361
|
-
if (img.inline || !img.objectId)
|
|
46435
|
+
if (img.inline || !img.objectId)
|
|
46436
|
+
return true;
|
|
46362
46437
|
const key = `${img.objectId.objNum}:${img.objectId.genNum}`;
|
|
46363
|
-
if (seenObjectIds.has(key))
|
|
46438
|
+
if (seenObjectIds.has(key))
|
|
46439
|
+
return false;
|
|
46364
46440
|
seenObjectIds.add(key);
|
|
46365
46441
|
return true;
|
|
46366
46442
|
}) : allExtracted;
|
|
@@ -46371,22 +46447,16 @@ async function runPdfimagesCli(argv, files) {
|
|
|
46371
46447
|
const root = positionals[1] ?? "image";
|
|
46372
46448
|
const printedFilenames = [];
|
|
46373
46449
|
for (let idx = 0; idx < extracted.length; idx++) {
|
|
46450
|
+
if (++cooperativeWork % 64 === 0)
|
|
46451
|
+
yield;
|
|
46374
46452
|
const img = extracted[idx];
|
|
46375
46453
|
const numStr = String(idx).padStart(3, "0");
|
|
46376
46454
|
const objField = img.inline || !img.objectId ? " [inline]" : `${String(img.objectId.objNum).padStart(6)} ${String(img.objectId.genNum).padStart(2)}`;
|
|
46377
46455
|
const sizeStr = formatPopplerSize(img.byteLength).padStart(5);
|
|
46378
|
-
const ratioStr = formatPopplerRatio(
|
|
46379
|
-
img.byteLength,
|
|
46380
|
-
img.width,
|
|
46381
|
-
img.height,
|
|
46382
|
-
img.components,
|
|
46383
|
-
img.bitsPerComponent
|
|
46384
|
-
).padStart(5);
|
|
46456
|
+
const ratioStr = formatPopplerRatio(img.byteLength, img.width, img.height, img.components, img.bitsPerComponent).padStart(5);
|
|
46385
46457
|
const interpStr = (img.interpolate ? "yes" : "no").padStart(6);
|
|
46386
46458
|
const colorCol = (img.colorSpaceLabel ?? img.colorSpace).padEnd(5);
|
|
46387
|
-
listLines.push(
|
|
46388
|
-
`${String(img.pageNumber).padStart(4)} ${String(idx).padStart(5)} ${img.type.padEnd(6)} ${String(img.width).padStart(5)} ${String(img.height).padStart(6)} ${colorCol} ${String(img.components).padStart(4)} ${String(img.bitsPerComponent).padStart(3)} ${img.encoding.padEnd(5)} ${interpStr} ${objField} ${String(img.xPpi).padStart(5)} ${String(img.yPpi).padStart(5)} ${sizeStr} ${ratioStr}`
|
|
46389
|
-
);
|
|
46459
|
+
listLines.push(`${String(img.pageNumber).padStart(4)} ${String(idx).padStart(5)} ${img.type.padEnd(6)} ${String(img.width).padStart(5)} ${String(img.height).padStart(6)} ${colorCol} ${String(img.components).padStart(4)} ${String(img.bitsPerComponent).padStart(3)} ${img.encoding.padEnd(5)} ${interpStr} ${objField} ${String(img.xPpi).padStart(5)} ${String(img.yPpi).padStart(5)} ${sizeStr} ${ratioStr}`);
|
|
46390
46460
|
if (!listOnly) {
|
|
46391
46461
|
let ext;
|
|
46392
46462
|
let outBytes;
|
|
@@ -46420,7 +46490,8 @@ async function runPdfimagesCli(argv, files) {
|
|
|
46420
46490
|
if (ext === "jb2e" && img.jbig2GlobalsBytes) {
|
|
46421
46491
|
const jb2gName = includePage ? `${root}-${String(img.pageNumber).padStart(3, "0")}-${numStr}.jb2g` : `${root}-${numStr}.jb2g`;
|
|
46422
46492
|
files.set(jb2gName, img.jbig2GlobalsBytes);
|
|
46423
|
-
if (printFilenames)
|
|
46493
|
+
if (printFilenames)
|
|
46494
|
+
printedFilenames.push(jb2gName);
|
|
46424
46495
|
}
|
|
46425
46496
|
if (ext === "ccitt") {
|
|
46426
46497
|
const paramsBase = includePage ? `${root}-${String(img.pageNumber).padStart(3, "0")}-${numStr}.params` : `${root}-${numStr}.params`;
|
|
@@ -46435,9 +46506,11 @@ async function runPdfimagesCli(argv, files) {
|
|
|
46435
46506
|
].join(" ");
|
|
46436
46507
|
files.set(paramsBase, new TextEncoder().encode(`${extraFlags}
|
|
46437
46508
|
`));
|
|
46438
|
-
if (printFilenames)
|
|
46509
|
+
if (printFilenames)
|
|
46510
|
+
printedFilenames.push(paramsBase);
|
|
46439
46511
|
}
|
|
46440
|
-
if (printFilenames)
|
|
46512
|
+
if (printFilenames)
|
|
46513
|
+
printedFilenames.push(outName);
|
|
46441
46514
|
}
|
|
46442
46515
|
}
|
|
46443
46516
|
if (listOnly) {
|
|
@@ -46448,6 +46521,9 @@ async function runPdfimagesCli(argv, files) {
|
|
|
46448
46521
|
}
|
|
46449
46522
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
46450
46523
|
}
|
|
46524
|
+
async function runPdfimagesCli(argv, files, signal) {
|
|
46525
|
+
return drainSteps(runPdfimagesCliSteps(argv, files, signal), signal);
|
|
46526
|
+
}
|
|
46451
46527
|
function copyDocumentMetadata(srcDoc, dstDoc) {
|
|
46452
46528
|
const meta = srcDoc.getMetadata();
|
|
46453
46529
|
if (meta.title) dstDoc.setTitle(meta.title);
|
|
@@ -46457,10 +46533,13 @@ function copyDocumentMetadata(srcDoc, dstDoc) {
|
|
|
46457
46533
|
if (meta.creator) dstDoc.setCreator(meta.creator);
|
|
46458
46534
|
if (meta.producer) dstDoc.setProducer(meta.producer);
|
|
46459
46535
|
}
|
|
46460
|
-
|
|
46536
|
+
function* runPdfuniteCliSteps(argv, files, signal) {
|
|
46537
|
+
let cooperativeWork = 63;
|
|
46461
46538
|
const positionals = [];
|
|
46462
46539
|
let password = "";
|
|
46463
46540
|
for (let i = 0; i < argv.length; i++) {
|
|
46541
|
+
if (++cooperativeWork % 64 === 0)
|
|
46542
|
+
yield;
|
|
46464
46543
|
const arg = argv[i];
|
|
46465
46544
|
if (arg === "-v" || arg === "--version") {
|
|
46466
46545
|
return { exitCode: 0, stdout: "pdfunite version 24.08.0\n", stderr: "" };
|
|
@@ -46476,7 +46555,8 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46476
46555
|
password = argv[++i] ?? "";
|
|
46477
46556
|
continue;
|
|
46478
46557
|
}
|
|
46479
|
-
if (!arg.startsWith("-"))
|
|
46558
|
+
if (!arg.startsWith("-"))
|
|
46559
|
+
positionals.push(arg);
|
|
46480
46560
|
}
|
|
46481
46561
|
if (positionals.length < 3) {
|
|
46482
46562
|
return {
|
|
@@ -46495,6 +46575,8 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46495
46575
|
const mergedPageLabelNums = [];
|
|
46496
46576
|
let pageOffset = 0;
|
|
46497
46577
|
for (const srcPath of sourcePaths) {
|
|
46578
|
+
if (++cooperativeWork % 64 === 0)
|
|
46579
|
+
yield;
|
|
46498
46580
|
const srcBytes = files.get(srcPath);
|
|
46499
46581
|
if (!srcBytes) {
|
|
46500
46582
|
return { exitCode: 1, stdout: "", stderr: `I/O Error: Couldn't open file '${srcPath}'
|
|
@@ -46512,6 +46594,8 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46512
46594
|
copiedMeta = true;
|
|
46513
46595
|
}
|
|
46514
46596
|
for (const att of collectEmbeddedAttachments(srcDoc)) {
|
|
46597
|
+
if (++cooperativeWork % 64 === 0)
|
|
46598
|
+
yield;
|
|
46515
46599
|
if (!seenAttachmentNames.has(att.name)) {
|
|
46516
46600
|
seenAttachmentNames.add(att.name);
|
|
46517
46601
|
mergedAttachments.push(att);
|
|
@@ -46519,7 +46603,8 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46519
46603
|
}
|
|
46520
46604
|
const srcCat = srcDoc.cos.resolveDict(srcDoc.cos.rootRef);
|
|
46521
46605
|
const collectSrcPageLabels = (plNode, visited = /* @__PURE__ */ new Set()) => {
|
|
46522
|
-
if (!plNode)
|
|
46606
|
+
if (!plNode)
|
|
46607
|
+
return;
|
|
46523
46608
|
const numsArr = srcDoc.cos.resolveArray(dictGet(plNode, "Nums"));
|
|
46524
46609
|
if (numsArr) {
|
|
46525
46610
|
for (let idx = 0; idx + 1 < numsArr.items.length; idx += 2) {
|
|
@@ -46530,9 +46615,12 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46530
46615
|
const sNode = srcDoc.cos.resolve(dictGet(vDict, "S"));
|
|
46531
46616
|
const stNode = srcDoc.cos.resolve(dictGet(vDict, "St"));
|
|
46532
46617
|
const pNode = srcDoc.cos.resolve(dictGet(vDict, "P"));
|
|
46533
|
-
if (sNode?.kind === "name")
|
|
46534
|
-
|
|
46535
|
-
if (
|
|
46618
|
+
if (sNode?.kind === "name")
|
|
46619
|
+
clonedEntries.S = cosName(sNode.decoded);
|
|
46620
|
+
if (stNode?.kind === "number")
|
|
46621
|
+
clonedEntries.St = cosNumber(stNode.value);
|
|
46622
|
+
if (pNode?.kind === "string")
|
|
46623
|
+
clonedEntries.P = { kind: "string", bytes: new Uint8Array(pNode.bytes), format: pNode.format };
|
|
46536
46624
|
mergedPageLabelNums.push(cosNumber(pageOffset + kNode.value), cosDict(clonedEntries));
|
|
46537
46625
|
}
|
|
46538
46626
|
}
|
|
@@ -46541,7 +46629,8 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46541
46629
|
if (kidsArr) {
|
|
46542
46630
|
for (const kid of kidsArr.items) {
|
|
46543
46631
|
if (kid.kind === "ref") {
|
|
46544
|
-
if (visited.has(kid.objectNumber))
|
|
46632
|
+
if (visited.has(kid.objectNumber))
|
|
46633
|
+
continue;
|
|
46545
46634
|
visited.add(kid.objectNumber);
|
|
46546
46635
|
}
|
|
46547
46636
|
collectSrcPageLabels(srcDoc.cos.resolveDict(kid), visited);
|
|
@@ -46556,11 +46645,13 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46556
46645
|
let cur = nodeOrRef;
|
|
46557
46646
|
while (cur) {
|
|
46558
46647
|
if (cur.kind === "ref") {
|
|
46559
|
-
if (visited.has(cur.objectNumber))
|
|
46648
|
+
if (visited.has(cur.objectNumber))
|
|
46649
|
+
break;
|
|
46560
46650
|
visited.add(cur.objectNumber);
|
|
46561
46651
|
}
|
|
46562
46652
|
const d = srcDoc.cos.resolveDict(cur);
|
|
46563
|
-
if (!d)
|
|
46653
|
+
if (!d)
|
|
46654
|
+
break;
|
|
46564
46655
|
const tNode = srcDoc.cos.resolve(dictGet(d, "Title"));
|
|
46565
46656
|
const title = tNode?.kind === "string" ? decodePdfString(tNode) : "";
|
|
46566
46657
|
const localPage = resolveDestinationPageIndex(srcDoc, dictGet(d, "Dest") ?? dictGet(d, "A")) ?? 0;
|
|
@@ -46568,11 +46659,13 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46568
46659
|
mergedOutlineItems.push({ title, targetPageIdx: pageOffset + localPage });
|
|
46569
46660
|
}
|
|
46570
46661
|
const firstChild = dictGet(d, "First");
|
|
46571
|
-
if (firstChild)
|
|
46662
|
+
if (firstChild)
|
|
46663
|
+
collectOutlinesFromSrc(firstChild, visited);
|
|
46572
46664
|
cur = dictGet(d, "Next");
|
|
46573
46665
|
}
|
|
46574
46666
|
};
|
|
46575
|
-
if (srcOutlines)
|
|
46667
|
+
if (srcOutlines)
|
|
46668
|
+
collectOutlinesFromSrc(dictGet(srcOutlines, "First"));
|
|
46576
46669
|
const indices = Array.from({ length: srcDoc.pageCount }, (_, idx) => idx);
|
|
46577
46670
|
merged.copyPagesFrom(srcDoc, indices);
|
|
46578
46671
|
pageOffset += srcDoc.pageCount;
|
|
@@ -46584,6 +46677,8 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46584
46677
|
const outlinesRef = merged.cos.allocateObject(outlinesDict);
|
|
46585
46678
|
const itemRefs = [];
|
|
46586
46679
|
for (const bm of mergedOutlineItems) {
|
|
46680
|
+
if (++cooperativeWork % 64 === 0)
|
|
46681
|
+
yield;
|
|
46587
46682
|
const pRef = merged.getPage(Math.min(merged.pageCount - 1, Math.max(0, bm.targetPageIdx))).ref;
|
|
46588
46683
|
const iDict = cosDict({
|
|
46589
46684
|
Title: { kind: "string", bytes: new TextEncoder().encode(bm.title), format: "literal" },
|
|
@@ -46613,21 +46708,19 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46613
46708
|
if (mergedAttachments.length > 0) {
|
|
46614
46709
|
const namesPairs = [];
|
|
46615
46710
|
for (const att of mergedAttachments) {
|
|
46616
|
-
|
|
46617
|
-
|
|
46618
|
-
|
|
46619
|
-
|
|
46620
|
-
|
|
46621
|
-
);
|
|
46711
|
+
if (++cooperativeWork % 64 === 0)
|
|
46712
|
+
yield;
|
|
46713
|
+
const efRef = merged.cos.allocateObject(cosStream(att.data, {
|
|
46714
|
+
dict: cosDict({ Type: cosName("EmbeddedFile") }),
|
|
46715
|
+
compress: true
|
|
46716
|
+
}));
|
|
46622
46717
|
const fnBytes = new TextEncoder().encode(att.name);
|
|
46623
|
-
const fsRef = merged.cos.allocateObject(
|
|
46624
|
-
|
|
46625
|
-
|
|
46626
|
-
|
|
46627
|
-
|
|
46628
|
-
|
|
46629
|
-
})
|
|
46630
|
-
);
|
|
46718
|
+
const fsRef = merged.cos.allocateObject(cosDict({
|
|
46719
|
+
Type: cosName("Filespec"),
|
|
46720
|
+
F: { kind: "string", bytes: fnBytes, format: "literal" },
|
|
46721
|
+
UF: { kind: "string", bytes: fnBytes, format: "literal" },
|
|
46722
|
+
EF: cosDict({ F: efRef, UF: efRef })
|
|
46723
|
+
}));
|
|
46631
46724
|
namesPairs.push({ kind: "string", bytes: fnBytes, format: "literal" }, fsRef);
|
|
46632
46725
|
}
|
|
46633
46726
|
const efTreeRef = merged.cos.allocateObject(cosDict({ Names: cosArray(namesPairs) }));
|
|
@@ -46646,6 +46739,9 @@ async function runPdfuniteCli(argv, files) {
|
|
|
46646
46739
|
files.set(destPath, merged.save());
|
|
46647
46740
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
46648
46741
|
}
|
|
46742
|
+
async function runPdfuniteCli(argv, files, signal) {
|
|
46743
|
+
return drainSteps(runPdfuniteCliSteps(argv, files, signal), signal);
|
|
46744
|
+
}
|
|
46649
46745
|
function parsePdfseparateSpec(pattern) {
|
|
46650
46746
|
let hasPageSpec = false;
|
|
46651
46747
|
for (let i = 0; i < pattern.length; i++) {
|
|
@@ -46698,12 +46794,15 @@ function parsePdfseparateSpec(pattern) {
|
|
|
46698
46794
|
}
|
|
46699
46795
|
};
|
|
46700
46796
|
}
|
|
46701
|
-
|
|
46797
|
+
function* runPdfseparateCliSteps(argv, files, signal) {
|
|
46798
|
+
let cooperativeWork = 63;
|
|
46702
46799
|
let firstPage = 1;
|
|
46703
46800
|
let lastPage = 0;
|
|
46704
46801
|
let password = "";
|
|
46705
46802
|
const positionals = [];
|
|
46706
46803
|
for (let i = 0; i < argv.length; i++) {
|
|
46804
|
+
if (++cooperativeWork % 64 === 0)
|
|
46805
|
+
yield;
|
|
46707
46806
|
const arg = argv[i];
|
|
46708
46807
|
if (arg === "-v" || arg === "--version") {
|
|
46709
46808
|
return { exitCode: 0, stdout: "pdfseparate version 24.08.0\n", stderr: "" };
|
|
@@ -46715,10 +46814,14 @@ async function runPdfseparateCli(argv, files) {
|
|
|
46715
46814
|
stderr: ""
|
|
46716
46815
|
};
|
|
46717
46816
|
}
|
|
46718
|
-
if (arg === "-f")
|
|
46719
|
-
|
|
46720
|
-
else if (arg === "-
|
|
46721
|
-
|
|
46817
|
+
if (arg === "-f")
|
|
46818
|
+
firstPage = Math.max(1, Number(argv[++i] ?? "1") || 1);
|
|
46819
|
+
else if (arg === "-l")
|
|
46820
|
+
lastPage = Math.max(0, Number(argv[++i] ?? "0") || 0);
|
|
46821
|
+
else if (arg === "-upw" || arg === "-opw")
|
|
46822
|
+
password = argv[++i] ?? "";
|
|
46823
|
+
else if (!arg.startsWith("-"))
|
|
46824
|
+
positionals.push(arg);
|
|
46722
46825
|
}
|
|
46723
46826
|
if (positionals.length < 2) {
|
|
46724
46827
|
return {
|
|
@@ -46761,6 +46864,7 @@ async function runPdfseparateCli(argv, files) {
|
|
|
46761
46864
|
};
|
|
46762
46865
|
}
|
|
46763
46866
|
for (let p = firstPage; p <= endPage; p++) {
|
|
46867
|
+
yield;
|
|
46764
46868
|
const singleDoc = PdfDocument.create();
|
|
46765
46869
|
copyDocumentMetadata(srcDoc, singleDoc);
|
|
46766
46870
|
singleDoc.copyPagesFrom(srcDoc, [p - 1]);
|
|
@@ -46769,6 +46873,9 @@ async function runPdfseparateCli(argv, files) {
|
|
|
46769
46873
|
}
|
|
46770
46874
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
46771
46875
|
}
|
|
46876
|
+
async function runPdfseparateCli(argv, files, signal) {
|
|
46877
|
+
return drainSteps(runPdfseparateCliSteps(argv, files, signal), signal);
|
|
46878
|
+
}
|
|
46772
46879
|
function isSubsetFontTag(fontName) {
|
|
46773
46880
|
if (fontName.length < 8 || fontName[6] !== "+") return false;
|
|
46774
46881
|
for (let i = 0; i < 6; i++) {
|
|
@@ -46777,10 +46884,8 @@ function isSubsetFontTag(fontName) {
|
|
|
46777
46884
|
}
|
|
46778
46885
|
return true;
|
|
46779
46886
|
}
|
|
46780
|
-
|
|
46781
|
-
|
|
46782
|
-
}
|
|
46783
|
-
function runPdffontsCliSync(argv, files) {
|
|
46887
|
+
function* runPdffontsCliSteps(argv, files, signal) {
|
|
46888
|
+
let cooperativeWork = 63;
|
|
46784
46889
|
let firstPage = 1;
|
|
46785
46890
|
let lastPage = 0;
|
|
46786
46891
|
let password = "";
|
|
@@ -46789,6 +46894,8 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46789
46894
|
let showSubst = false;
|
|
46790
46895
|
const positionals = [];
|
|
46791
46896
|
for (let i = 0; i < argv.length; i++) {
|
|
46897
|
+
if (++cooperativeWork % 64 === 0)
|
|
46898
|
+
yield;
|
|
46792
46899
|
const arg = argv[i];
|
|
46793
46900
|
if (arg === "-v" || arg === "--version") {
|
|
46794
46901
|
return { exitCode: 0, stdout: "pdffonts version 24.08.0\n", stderr: "" };
|
|
@@ -46800,15 +46907,21 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46800
46907
|
stderr: ""
|
|
46801
46908
|
};
|
|
46802
46909
|
}
|
|
46803
|
-
if (arg === "-f")
|
|
46804
|
-
|
|
46805
|
-
else if (arg === "-
|
|
46806
|
-
|
|
46910
|
+
if (arg === "-f")
|
|
46911
|
+
firstPage = Math.max(1, Number.parseInt(argv[++i] ?? "1", 10) || 1);
|
|
46912
|
+
else if (arg === "-l")
|
|
46913
|
+
lastPage = Math.max(0, Number.parseInt(argv[++i] ?? "0", 10) || 0);
|
|
46914
|
+
else if (arg === "-upw" || arg === "-opw")
|
|
46915
|
+
password = argv[++i] ?? "";
|
|
46916
|
+
else if (arg === "-loc")
|
|
46917
|
+
showLoc = true;
|
|
46807
46918
|
else if (arg === "-locPS") {
|
|
46808
46919
|
showLoc = true;
|
|
46809
46920
|
showLocPs = true;
|
|
46810
|
-
} else if (arg === "-subst")
|
|
46811
|
-
|
|
46921
|
+
} else if (arg === "-subst")
|
|
46922
|
+
showSubst = true;
|
|
46923
|
+
else if (!arg.startsWith("-") || arg === "-")
|
|
46924
|
+
positionals.push(arg);
|
|
46812
46925
|
}
|
|
46813
46926
|
const inputPath = positionals[0] ?? (files.has("-") ? "-" : void 0);
|
|
46814
46927
|
if (!inputPath) {
|
|
@@ -46848,16 +46961,19 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46848
46961
|
"------------------------------------ ----------------- ---------------- --- --- --- ---------"
|
|
46849
46962
|
];
|
|
46850
46963
|
const collectFontsFromResources = (resDict, visitedForms = /* @__PURE__ */ new Set()) => {
|
|
46851
|
-
if (!resDict)
|
|
46964
|
+
if (!resDict)
|
|
46965
|
+
return;
|
|
46852
46966
|
const fontMap = cos.resolveDict(dictGet(resDict, "Font"));
|
|
46853
46967
|
if (fontMap) {
|
|
46854
46968
|
for (const entry of fontMap.entries) {
|
|
46855
46969
|
const rawVal = entry.value;
|
|
46856
46970
|
const objKey = rawVal.kind === "ref" ? `${rawVal.objectNumber}:${rawVal.generationNumber}` : `inline:${entry.key.decoded}`;
|
|
46857
|
-
if (seenFontKeys.has(objKey))
|
|
46971
|
+
if (seenFontKeys.has(objKey))
|
|
46972
|
+
continue;
|
|
46858
46973
|
seenFontKeys.add(objKey);
|
|
46859
46974
|
const fontDict = cos.resolveDict(rawVal);
|
|
46860
|
-
if (!fontDict)
|
|
46975
|
+
if (!fontDict)
|
|
46976
|
+
continue;
|
|
46861
46977
|
const baseFontNode = cos.resolve(dictGet(fontDict, "BaseFont") ?? dictGet(fontDict, "Name"));
|
|
46862
46978
|
const fontName = baseFontNode?.kind === "name" ? baseFontNode.decoded : baseFontNode?.kind === "string" ? decodePdfString(baseFontNode) : "[none]";
|
|
46863
46979
|
const subtypeNode = cos.resolve(dictGet(fontDict, "Subtype"));
|
|
@@ -46870,13 +46986,14 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46870
46986
|
}
|
|
46871
46987
|
}
|
|
46872
46988
|
const descriptorDict = cos.resolveDict(dictGet(fontDict, "FontDescriptor")) ?? (descFontDict ? cos.resolveDict(dictGet(descFontDict, "FontDescriptor")) : void 0);
|
|
46873
|
-
const hasEmbeddedFile = Boolean(
|
|
46874
|
-
rawSubtype === "Type3" || descriptorDict && (dictGet(descriptorDict, "FontFile") || dictGet(descriptorDict, "FontFile2") || dictGet(descriptorDict, "FontFile3"))
|
|
46875
|
-
);
|
|
46989
|
+
const hasEmbeddedFile = Boolean(rawSubtype === "Type3" || descriptorDict && (dictGet(descriptorDict, "FontFile") || dictGet(descriptorDict, "FontFile2") || dictGet(descriptorDict, "FontFile3")));
|
|
46876
46990
|
let fontTypeLabel = "Type 1";
|
|
46877
|
-
if (rawSubtype === "TrueType")
|
|
46878
|
-
|
|
46879
|
-
else if (rawSubtype === "
|
|
46991
|
+
if (rawSubtype === "TrueType")
|
|
46992
|
+
fontTypeLabel = "TrueType";
|
|
46993
|
+
else if (rawSubtype === "MMType1")
|
|
46994
|
+
fontTypeLabel = "MM Type 1";
|
|
46995
|
+
else if (rawSubtype === "Type3")
|
|
46996
|
+
fontTypeLabel = "Type 3";
|
|
46880
46997
|
else if (rawSubtype === "Type0") {
|
|
46881
46998
|
const descSubtype = descFontDict ? cos.resolve(dictGet(descFontDict, "Subtype")) : void 0;
|
|
46882
46999
|
fontTypeLabel = descSubtype?.kind === "name" && descSubtype.decoded === "CIDFontType2" ? "CID TrueType" : "CID Type 0";
|
|
@@ -46887,10 +47004,14 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46887
47004
|
let encodingLabel = "Builtin";
|
|
46888
47005
|
if (encNode?.kind === "name") {
|
|
46889
47006
|
const eName = encNode.decoded;
|
|
46890
|
-
if (eName === "WinAnsiEncoding")
|
|
46891
|
-
|
|
46892
|
-
else if (eName === "
|
|
46893
|
-
|
|
47007
|
+
if (eName === "WinAnsiEncoding")
|
|
47008
|
+
encodingLabel = "WinAnsi";
|
|
47009
|
+
else if (eName === "MacRomanEncoding")
|
|
47010
|
+
encodingLabel = "MacRoman";
|
|
47011
|
+
else if (eName === "StandardEncoding")
|
|
47012
|
+
encodingLabel = "Standard";
|
|
47013
|
+
else
|
|
47014
|
+
encodingLabel = eName;
|
|
46894
47015
|
} else if (encNode?.kind === "dict") {
|
|
46895
47016
|
encodingLabel = "Custom";
|
|
46896
47017
|
}
|
|
@@ -46908,14 +47029,10 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46908
47029
|
else if (fontName === "Symbol") subFontName = "Standard Symbols PS";
|
|
46909
47030
|
else if (fontName === "ZapfDingbats") subFontName = "D050000L";
|
|
46910
47031
|
const subFontFile = `/usr/share/fonts/type1/urw-base35/${subFontName.replaceAll(" ", "")}.t1`;
|
|
46911
|
-
rows.push(
|
|
46912
|
-
`${fontName.slice(0, 36).padEnd(36)} ${objIdStr} ${subFontName.slice(0, 36).padEnd(36)} ${subFontFile}`
|
|
46913
|
-
);
|
|
47032
|
+
rows.push(`${fontName.slice(0, 36).padEnd(36)} ${objIdStr} ${subFontName.slice(0, 36).padEnd(36)} ${subFontFile}`);
|
|
46914
47033
|
}
|
|
46915
47034
|
} else {
|
|
46916
|
-
rows.push(
|
|
46917
|
-
`${fontName.slice(0, 36).padEnd(36)} ${fontTypeLabel.padEnd(17)} ${encodingLabel.slice(0, 16).padEnd(16)} ${embStr} ${subStr} ${uniStr} ${objIdStr}${locSuffix}`
|
|
46918
|
-
);
|
|
47035
|
+
rows.push(`${fontName.slice(0, 36).padEnd(36)} ${fontTypeLabel.padEnd(17)} ${encodingLabel.slice(0, 16).padEnd(16)} ${embStr} ${subStr} ${uniStr} ${objIdStr}${locSuffix}`);
|
|
46919
47036
|
}
|
|
46920
47037
|
if (rawSubtype === "Type3") {
|
|
46921
47038
|
collectFontsFromResources(cos.resolveDict(dictGet(fontDict, "Resources")), visitedForms);
|
|
@@ -46928,10 +47045,7 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46928
47045
|
const gsDict = cos.resolveDict(gsEntry.value);
|
|
46929
47046
|
const gsFontArr = gsDict ? cos.resolveArray(dictGet(gsDict, "Font")) : void 0;
|
|
46930
47047
|
if (gsFontArr && gsFontArr.items.length >= 1) {
|
|
46931
|
-
collectFontsFromResources(
|
|
46932
|
-
{ kind: "dict", entries: [{ key: { kind: "name", decoded: "Font", rawBytes: new Uint8Array(0) }, value: { kind: "dict", entries: [{ key: { kind: "name", decoded: `ExtGS_${gsEntry.key.decoded}`, rawBytes: new Uint8Array(0) }, value: gsFontArr.items[0] }] } }] },
|
|
46933
|
-
visitedForms
|
|
46934
|
-
);
|
|
47048
|
+
collectFontsFromResources({ kind: "dict", entries: [{ key: { kind: "name", decoded: "Font", rawBytes: new Uint8Array(0) }, value: { kind: "dict", entries: [{ key: { kind: "name", decoded: `ExtGS_${gsEntry.key.decoded}`, rawBytes: new Uint8Array(0) }, value: gsFontArr.items[0] }] } }] }, visitedForms);
|
|
46935
47049
|
}
|
|
46936
47050
|
}
|
|
46937
47051
|
}
|
|
@@ -46939,7 +47053,8 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46939
47053
|
if (xobjMap) {
|
|
46940
47054
|
for (const entry of xobjMap.entries) {
|
|
46941
47055
|
if (entry.value.kind === "ref") {
|
|
46942
|
-
if (visitedForms.has(entry.value.objectNumber))
|
|
47056
|
+
if (visitedForms.has(entry.value.objectNumber))
|
|
47057
|
+
continue;
|
|
46943
47058
|
visitedForms.add(entry.value.objectNumber);
|
|
46944
47059
|
}
|
|
46945
47060
|
const xobj = cos.resolve(entry.value);
|
|
@@ -46955,7 +47070,8 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46955
47070
|
if (patMap) {
|
|
46956
47071
|
for (const entry of patMap.entries) {
|
|
46957
47072
|
if (entry.value.kind === "ref") {
|
|
46958
|
-
if (visitedForms.has(entry.value.objectNumber))
|
|
47073
|
+
if (visitedForms.has(entry.value.objectNumber))
|
|
47074
|
+
continue;
|
|
46959
47075
|
visitedForms.add(entry.value.objectNumber);
|
|
46960
47076
|
}
|
|
46961
47077
|
const pat = cos.resolve(entry.value);
|
|
@@ -46969,20 +47085,28 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46969
47085
|
const acroFormDict = rootDict ? cos.resolveDict(dictGet(rootDict, "AcroForm")) : void 0;
|
|
46970
47086
|
const acroDrDict = acroFormDict ? cos.resolveDict(dictGet(acroFormDict, "DR")) : void 0;
|
|
46971
47087
|
for (let p = firstPage; p <= endPage; p++) {
|
|
47088
|
+
yield;
|
|
46972
47089
|
const page = doc.getPage(p - 1);
|
|
46973
47090
|
collectFontsFromResources(page.getResourcesDict());
|
|
46974
47091
|
const annots = cos.resolveArray(dictGet(page.pageDict, "Annots"));
|
|
46975
47092
|
if (annots) {
|
|
46976
47093
|
for (const item of annots.items) {
|
|
47094
|
+
if (++cooperativeWork % 64 === 0)
|
|
47095
|
+
yield;
|
|
46977
47096
|
const annotDict = cos.resolveDict(item);
|
|
46978
47097
|
const apDict = annotDict ? cos.resolveDict(dictGet(annotDict, "AP")) : void 0;
|
|
46979
|
-
if (!apDict)
|
|
47098
|
+
if (!apDict)
|
|
47099
|
+
continue;
|
|
46980
47100
|
for (const apKey of ["N", "R", "D"]) {
|
|
47101
|
+
if (++cooperativeWork % 64 === 0)
|
|
47102
|
+
yield;
|
|
46981
47103
|
const apVal = cos.resolve(dictGet(apDict, apKey));
|
|
46982
47104
|
if (apVal?.kind === "stream") {
|
|
46983
47105
|
collectFontsFromResources(cos.resolveDict(dictGet(apVal.dict, "Resources")));
|
|
46984
47106
|
} else if (apVal?.kind === "dict") {
|
|
46985
47107
|
for (const sub of apVal.entries) {
|
|
47108
|
+
if (++cooperativeWork % 64 === 0)
|
|
47109
|
+
yield;
|
|
46986
47110
|
const subStream = cos.resolve(sub.value);
|
|
46987
47111
|
if (subStream?.kind === "stream") {
|
|
46988
47112
|
collectFontsFromResources(cos.resolveDict(dictGet(subStream.dict, "Resources")));
|
|
@@ -46998,6 +47122,17 @@ function runPdffontsCliSync(argv, files) {
|
|
|
46998
47122
|
}
|
|
46999
47123
|
return { exitCode: 0, stdout: rows.join("\n") + "\n", stderr: "" };
|
|
47000
47124
|
}
|
|
47125
|
+
async function runPdffontsCli(argv, files, signal) {
|
|
47126
|
+
return drainSteps(runPdffontsCliSteps(argv, files, signal), signal);
|
|
47127
|
+
}
|
|
47128
|
+
function runPdffontsCliSync(argv, files, signal) {
|
|
47129
|
+
const steps = runPdffontsCliSteps(argv, files, signal);
|
|
47130
|
+
let next = steps.next();
|
|
47131
|
+
while (!next.done) {
|
|
47132
|
+
next = steps.next();
|
|
47133
|
+
}
|
|
47134
|
+
return next.value;
|
|
47135
|
+
}
|
|
47001
47136
|
function collectEmbeddedAttachments(doc) {
|
|
47002
47137
|
const cos = doc.cos;
|
|
47003
47138
|
const results = [];
|
|
@@ -47069,7 +47204,8 @@ function collectEmbeddedAttachments(doc) {
|
|
|
47069
47204
|
}
|
|
47070
47205
|
return results;
|
|
47071
47206
|
}
|
|
47072
|
-
function
|
|
47207
|
+
function* runPdfdetachCliSteps(argv, files, signal) {
|
|
47208
|
+
let cooperativeWork = 63;
|
|
47073
47209
|
let listOnly = false;
|
|
47074
47210
|
let saveNumber = 0;
|
|
47075
47211
|
let saveFileName = "";
|
|
@@ -47079,6 +47215,8 @@ function runPdfdetachCliSync(argv, files) {
|
|
|
47079
47215
|
let encoding = "UTF-8";
|
|
47080
47216
|
const positionals = [];
|
|
47081
47217
|
for (let i = 0; i < argv.length; i++) {
|
|
47218
|
+
if (++cooperativeWork % 64 === 0)
|
|
47219
|
+
yield;
|
|
47082
47220
|
const arg = argv[i];
|
|
47083
47221
|
if (arg === "-v" || arg === "--version") {
|
|
47084
47222
|
return { exitCode: 0, stdout: "pdfdetach version 24.08.0\n", stderr: "" };
|
|
@@ -47090,12 +47228,18 @@ function runPdfdetachCliSync(argv, files) {
|
|
|
47090
47228
|
stderr: ""
|
|
47091
47229
|
};
|
|
47092
47230
|
}
|
|
47093
|
-
if (arg === "-list")
|
|
47094
|
-
|
|
47095
|
-
else if (arg === "-
|
|
47096
|
-
|
|
47097
|
-
else if (arg === "-
|
|
47098
|
-
|
|
47231
|
+
if (arg === "-list")
|
|
47232
|
+
listOnly = true;
|
|
47233
|
+
else if (arg === "-save")
|
|
47234
|
+
saveNumber = Number.parseInt(argv[++i] ?? "0", 10) || 0;
|
|
47235
|
+
else if (arg === "-savefile")
|
|
47236
|
+
saveFileName = argv[++i] ?? "";
|
|
47237
|
+
else if (arg === "-saveall")
|
|
47238
|
+
saveAll = true;
|
|
47239
|
+
else if (arg === "-o")
|
|
47240
|
+
outputPath = argv[++i] ?? "";
|
|
47241
|
+
else if (arg === "-upw" || arg === "-opw")
|
|
47242
|
+
password = argv[++i] ?? "";
|
|
47099
47243
|
else if (arg === "-enc") {
|
|
47100
47244
|
const nextEnc = argv[++i] ?? "";
|
|
47101
47245
|
if (!SUPPORTED_ENCODINGS.has(nextEnc)) {
|
|
@@ -47107,7 +47251,8 @@ function runPdfdetachCliSync(argv, files) {
|
|
|
47107
47251
|
};
|
|
47108
47252
|
}
|
|
47109
47253
|
encoding = nextEnc;
|
|
47110
|
-
} else if (!arg.startsWith("-") || arg === "-")
|
|
47254
|
+
} else if (!arg.startsWith("-") || arg === "-")
|
|
47255
|
+
positionals.push(arg);
|
|
47111
47256
|
}
|
|
47112
47257
|
const inputPath = positionals[0] ?? (files.has("-") ? "-" : void 0);
|
|
47113
47258
|
if (!inputPath) {
|
|
@@ -47129,6 +47274,8 @@ function runPdfdetachCliSync(argv, files) {
|
|
|
47129
47274
|
if (listOnly || !saveNumber && !saveFileName && !saveAll) {
|
|
47130
47275
|
const lines = [`${attachments.length} embedded files`];
|
|
47131
47276
|
for (let i = 0; i < attachments.length; i++) {
|
|
47277
|
+
if (++cooperativeWork % 64 === 0)
|
|
47278
|
+
yield;
|
|
47132
47279
|
const attName = applyPopplerOutputEncoding(attachments[i].name, encoding);
|
|
47133
47280
|
lines.push(`${i + 1}: ${attName}`);
|
|
47134
47281
|
}
|
|
@@ -47157,13 +47304,23 @@ function runPdfdetachCliSync(argv, files) {
|
|
|
47157
47304
|
if (saveAll) {
|
|
47158
47305
|
const prefix = outputPath ? outputPath.endsWith("/") ? outputPath.slice(0, -1) : outputPath : "";
|
|
47159
47306
|
for (const att of attachments) {
|
|
47307
|
+
if (++cooperativeWork % 64 === 0)
|
|
47308
|
+
yield;
|
|
47160
47309
|
files.set(prefix ? `${prefix}/${att.name}` : att.name, att.data);
|
|
47161
47310
|
}
|
|
47162
47311
|
}
|
|
47163
47312
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
47164
47313
|
}
|
|
47165
|
-
async function runPdfdetachCli(argv, files) {
|
|
47166
|
-
return
|
|
47314
|
+
async function runPdfdetachCli(argv, files, signal) {
|
|
47315
|
+
return drainSteps(runPdfdetachCliSteps(argv, files, signal), signal);
|
|
47316
|
+
}
|
|
47317
|
+
function runPdfdetachCliSync(argv, files, signal) {
|
|
47318
|
+
const steps = runPdfdetachCliSteps(argv, files, signal);
|
|
47319
|
+
let next = steps.next();
|
|
47320
|
+
while (!next.done) {
|
|
47321
|
+
next = steps.next();
|
|
47322
|
+
}
|
|
47323
|
+
return next.value;
|
|
47167
47324
|
}
|
|
47168
47325
|
var POPPLER_FILE_TOOL_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
47169
47326
|
"-r",
|
|
@@ -47213,6 +47370,7 @@ function extractPopplerFileToolPositionals(argv) {
|
|
|
47213
47370
|
return pos;
|
|
47214
47371
|
}
|
|
47215
47372
|
async function executePopplerFileTool(context, runner) {
|
|
47373
|
+
let cooperativeWork = 63;
|
|
47216
47374
|
const invocation = createOutputOperation(context, { write: async () => {
|
|
47217
47375
|
} });
|
|
47218
47376
|
try {
|
|
@@ -47232,6 +47390,7 @@ async function executePopplerFileTool(context, runner) {
|
|
|
47232
47390
|
const chunks = [];
|
|
47233
47391
|
let total = 0;
|
|
47234
47392
|
for await (const chunk of readBytes(context.stdin, invocation.signal)) {
|
|
47393
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
47235
47394
|
chunks.push(chunk);
|
|
47236
47395
|
total += chunk.byteLength;
|
|
47237
47396
|
chargeBytes(chunk.byteLength);
|
|
@@ -47240,6 +47399,7 @@ async function executePopplerFileTool(context, runner) {
|
|
|
47240
47399
|
const buf = new Uint8Array(total);
|
|
47241
47400
|
let off = 0;
|
|
47242
47401
|
for (const c of chunks) {
|
|
47402
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
47243
47403
|
buf.set(c, off);
|
|
47244
47404
|
off += c.byteLength;
|
|
47245
47405
|
}
|
|
@@ -47247,6 +47407,7 @@ async function executePopplerFileTool(context, runner) {
|
|
|
47247
47407
|
}
|
|
47248
47408
|
}
|
|
47249
47409
|
for (const token of positionals) {
|
|
47410
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
47250
47411
|
if (token === "-") continue;
|
|
47251
47412
|
try {
|
|
47252
47413
|
const bytes = await context.fs.readFile(resolveVfsPath(token), { signal: invocation.signal });
|
|
@@ -47255,8 +47416,9 @@ async function executePopplerFileTool(context, runner) {
|
|
|
47255
47416
|
} catch {
|
|
47256
47417
|
}
|
|
47257
47418
|
}
|
|
47419
|
+
context.inputBudget?.check(0);
|
|
47258
47420
|
const existingSnap = new Map(vfsFiles);
|
|
47259
|
-
const res = await runner(argv, vfsFiles);
|
|
47421
|
+
const res = await runner(argv, vfsFiles, invocation.signal);
|
|
47260
47422
|
if (res.stderr) {
|
|
47261
47423
|
await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
|
|
47262
47424
|
}
|
|
@@ -47271,6 +47433,7 @@ async function executePopplerFileTool(context, runner) {
|
|
|
47271
47433
|
await writeBytes(stdout.output, outBytes, invocation.signal);
|
|
47272
47434
|
}
|
|
47273
47435
|
for (const [key, val] of vfsFiles.entries()) {
|
|
47436
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
47274
47437
|
if (key !== "-" && existingSnap.get(key) !== val) {
|
|
47275
47438
|
chargeBytes(val.byteLength);
|
|
47276
47439
|
const abs = resolveVfsPath(key);
|
|
@@ -47287,73 +47450,92 @@ async function executePopplerFileTool(context, runner) {
|
|
|
47287
47450
|
await invocation.close();
|
|
47288
47451
|
}
|
|
47289
47452
|
}
|
|
47290
|
-
function createPdftoppmCommand(
|
|
47453
|
+
function createPdftoppmCommand(options = {}) {
|
|
47454
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
47291
47455
|
return Object.freeze({
|
|
47292
47456
|
name: "pdftoppm",
|
|
47293
47457
|
runtimeIdentity: commandRuntimeIdentity,
|
|
47294
47458
|
description: "Render PDF pages to PNG, PPM, PGM, or PBM images via @poe-code/pdf-ast",
|
|
47295
47459
|
execute(context) {
|
|
47296
|
-
return
|
|
47460
|
+
return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
|
|
47461
|
+
return executePopplerFileTool(context2, runPdftoppmCli);
|
|
47462
|
+
});
|
|
47297
47463
|
}
|
|
47298
47464
|
});
|
|
47299
47465
|
}
|
|
47300
47466
|
var pdftoppmCommand = createPdftoppmCommand();
|
|
47301
|
-
function createPdfimagesCommand(
|
|
47467
|
+
function createPdfimagesCommand(options = {}) {
|
|
47468
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
47302
47469
|
return Object.freeze({
|
|
47303
47470
|
name: "pdfimages",
|
|
47304
47471
|
runtimeIdentity: commandRuntimeIdentity,
|
|
47305
47472
|
description: "List and extract embedded images from PDF pages via @poe-code/pdf-ast",
|
|
47306
47473
|
execute(context) {
|
|
47307
|
-
return
|
|
47474
|
+
return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
|
|
47475
|
+
return executePopplerFileTool(context2, runPdfimagesCli);
|
|
47476
|
+
});
|
|
47308
47477
|
}
|
|
47309
47478
|
});
|
|
47310
47479
|
}
|
|
47311
47480
|
var pdfimagesCommand = createPdfimagesCommand();
|
|
47312
|
-
function createPdfuniteCommand(
|
|
47481
|
+
function createPdfuniteCommand(options = {}) {
|
|
47482
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
47313
47483
|
return Object.freeze({
|
|
47314
47484
|
name: "pdfunite",
|
|
47315
47485
|
runtimeIdentity: commandRuntimeIdentity,
|
|
47316
47486
|
description: "Merge multiple PDF documents into a single PDF via @poe-code/pdf-ast",
|
|
47317
47487
|
execute(context) {
|
|
47318
|
-
return
|
|
47488
|
+
return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
|
|
47489
|
+
return executePopplerFileTool(context2, runPdfuniteCli);
|
|
47490
|
+
});
|
|
47319
47491
|
}
|
|
47320
47492
|
});
|
|
47321
47493
|
}
|
|
47322
47494
|
var pdfuniteCommand = createPdfuniteCommand();
|
|
47323
|
-
function createPdfseparateCommand(
|
|
47495
|
+
function createPdfseparateCommand(options = {}) {
|
|
47496
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
47324
47497
|
return Object.freeze({
|
|
47325
47498
|
name: "pdfseparate",
|
|
47326
47499
|
runtimeIdentity: commandRuntimeIdentity,
|
|
47327
47500
|
description: "Split PDF pages into individual PDF files via @poe-code/pdf-ast",
|
|
47328
47501
|
execute(context) {
|
|
47329
|
-
return
|
|
47502
|
+
return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
|
|
47503
|
+
return executePopplerFileTool(context2, runPdfseparateCli);
|
|
47504
|
+
});
|
|
47330
47505
|
}
|
|
47331
47506
|
});
|
|
47332
47507
|
}
|
|
47333
47508
|
var pdfseparateCommand = createPdfseparateCommand();
|
|
47334
|
-
function createPdffontsCommand(
|
|
47509
|
+
function createPdffontsCommand(options = {}) {
|
|
47510
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
47335
47511
|
return Object.freeze({
|
|
47336
47512
|
name: "pdffonts",
|
|
47337
47513
|
runtimeIdentity: commandRuntimeIdentity,
|
|
47338
47514
|
description: "List fonts used in a PDF document via @poe-code/pdf-ast",
|
|
47339
47515
|
execute(context) {
|
|
47340
|
-
return
|
|
47516
|
+
return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
|
|
47517
|
+
return executePopplerFileTool(context2, runPdffontsCli);
|
|
47518
|
+
});
|
|
47341
47519
|
}
|
|
47342
47520
|
});
|
|
47343
47521
|
}
|
|
47344
47522
|
var pdffontsCommand = createPdffontsCommand();
|
|
47345
|
-
function createPdfdetachCommand(
|
|
47523
|
+
function createPdfdetachCommand(options = {}) {
|
|
47524
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
47346
47525
|
return Object.freeze({
|
|
47347
47526
|
name: "pdfdetach",
|
|
47348
47527
|
runtimeIdentity: commandRuntimeIdentity,
|
|
47349
47528
|
description: "List and extract embedded file attachments from PDF documents via @poe-code/pdf-ast",
|
|
47350
47529
|
execute(context) {
|
|
47351
|
-
return
|
|
47530
|
+
return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
|
|
47531
|
+
return executePopplerFileTool(context2, runPdfdetachCli);
|
|
47532
|
+
});
|
|
47352
47533
|
}
|
|
47353
47534
|
});
|
|
47354
47535
|
}
|
|
47355
47536
|
var pdfdetachCommand = createPdfdetachCommand();
|
|
47356
|
-
|
|
47537
|
+
function* runPdftocairoCliSteps(argv, files, signal) {
|
|
47538
|
+
let cooperativeWork = 63;
|
|
47357
47539
|
let format = "png";
|
|
47358
47540
|
let grayMode = false;
|
|
47359
47541
|
let monoMode = false;
|
|
@@ -47371,6 +47553,8 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47371
47553
|
const forwardedArgs = [];
|
|
47372
47554
|
const positionals = [];
|
|
47373
47555
|
for (let i = 0; i < argv.length; i++) {
|
|
47556
|
+
if (++cooperativeWork % 64 === 0)
|
|
47557
|
+
yield;
|
|
47374
47558
|
const arg = argv[i];
|
|
47375
47559
|
if (arg === "-v" || arg === "--version") {
|
|
47376
47560
|
return { exitCode: 0, stdout: "pdftocairo version 24.08.0\n", stderr: "" };
|
|
@@ -47391,12 +47575,18 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47391
47575
|
} else if (arg === "-tiff") {
|
|
47392
47576
|
format = "tif";
|
|
47393
47577
|
forwardedArgs.push("-tiff");
|
|
47394
|
-
} else if (arg === "-svg")
|
|
47395
|
-
|
|
47396
|
-
else if (arg === "-
|
|
47397
|
-
|
|
47398
|
-
else if (arg === "-
|
|
47399
|
-
|
|
47578
|
+
} else if (arg === "-svg")
|
|
47579
|
+
format = "svg";
|
|
47580
|
+
else if (arg === "-pdf")
|
|
47581
|
+
format = "pdf";
|
|
47582
|
+
else if (arg === "-ps")
|
|
47583
|
+
format = "ps";
|
|
47584
|
+
else if (arg === "-eps")
|
|
47585
|
+
format = "eps";
|
|
47586
|
+
else if (arg === "-gray")
|
|
47587
|
+
grayMode = true;
|
|
47588
|
+
else if (arg === "-mono")
|
|
47589
|
+
monoMode = true;
|
|
47400
47590
|
else if (arg === "-antialias") {
|
|
47401
47591
|
const m = (argv[++i] ?? "").toLowerCase();
|
|
47402
47592
|
if (!["default", "none", "gray", "subpixel", "fast", "good", "best"].includes(m)) {
|
|
@@ -47405,8 +47595,10 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47405
47595
|
} else if (POPPLER_FILE_TOOL_VALUE_FLAGS.has(arg)) {
|
|
47406
47596
|
const v = argv[++i] ?? "";
|
|
47407
47597
|
forwardedArgs.push(arg, v);
|
|
47408
|
-
if (arg === "-f")
|
|
47409
|
-
|
|
47598
|
+
if (arg === "-f")
|
|
47599
|
+
firstPage = Math.max(1, Number.parseInt(v, 10) || 1);
|
|
47600
|
+
else if (arg === "-l")
|
|
47601
|
+
lastPage = Math.max(0, Number.parseInt(v, 10) || 0);
|
|
47410
47602
|
else if (arg === "-x") {
|
|
47411
47603
|
cropX = Math.max(0, Number.parseInt(v, 10) || 0);
|
|
47412
47604
|
hasCrop = true;
|
|
@@ -47419,7 +47611,8 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47419
47611
|
} else if (arg === "-H") {
|
|
47420
47612
|
cropH = Math.max(0, Number.parseInt(v, 10) || 0);
|
|
47421
47613
|
hasCrop = true;
|
|
47422
|
-
} else if (arg === "-upw" || arg === "-opw")
|
|
47614
|
+
} else if (arg === "-upw" || arg === "-opw")
|
|
47615
|
+
password = v;
|
|
47423
47616
|
} else if (arg.startsWith("-") && arg !== "-") {
|
|
47424
47617
|
forwardedArgs.push(arg);
|
|
47425
47618
|
} else {
|
|
@@ -47434,11 +47627,12 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47434
47627
|
if (format === "svg") {
|
|
47435
47628
|
const rawOut = positionals[1] ?? (inputPath === "-" ? "-" : `${inputStem}.svg`);
|
|
47436
47629
|
const rootForSvg = rawOut.toLowerCase().endsWith(".svg") ? rawOut.slice(0, -4) : rawOut;
|
|
47437
|
-
return
|
|
47630
|
+
return yield* runPdftoppmCliSteps(["-svg", "-singlefile", ...forwardedArgs, inputPath, rootForSvg], files, signal);
|
|
47438
47631
|
}
|
|
47439
47632
|
if (format === "pdf" || format === "ps" || format === "eps") {
|
|
47440
47633
|
const pdfBytes = files.get(inputPath);
|
|
47441
|
-
if (!pdfBytes)
|
|
47634
|
+
if (!pdfBytes)
|
|
47635
|
+
return { exitCode: 1, stdout: "", stderr: `I/O Error: Couldn't open file '${inputPath}'
|
|
47442
47636
|
` };
|
|
47443
47637
|
const doc = PdfDocument.load(pdfBytes, password ? { password } : void 0);
|
|
47444
47638
|
const endPage = lastPage > 0 ? Math.min(doc.pageCount, lastPage) : doc.pageCount;
|
|
@@ -47450,6 +47644,7 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47450
47644
|
if (format === "pdf") {
|
|
47451
47645
|
const outDoc = PdfDocument.create();
|
|
47452
47646
|
for (let p = firstPage; p <= endPage; p++) {
|
|
47647
|
+
yield;
|
|
47453
47648
|
const [copied] = outDoc.copyPagesFrom(doc, [p - 1]);
|
|
47454
47649
|
if (copied && hasCrop) {
|
|
47455
47650
|
const origSize = copied.getSize();
|
|
@@ -47460,7 +47655,8 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47460
47655
|
}
|
|
47461
47656
|
}
|
|
47462
47657
|
const outBytes = outDoc.save();
|
|
47463
|
-
if (finalOut === "-")
|
|
47658
|
+
if (finalOut === "-")
|
|
47659
|
+
return { exitCode: 0, stdout: "", stderr: "", stdoutBytes: outBytes };
|
|
47464
47660
|
files.set(finalOut, outBytes);
|
|
47465
47661
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
47466
47662
|
}
|
|
@@ -47472,10 +47668,14 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47472
47668
|
"%%EndComments"
|
|
47473
47669
|
];
|
|
47474
47670
|
for (let p = firstPage; p <= endPage; p++) {
|
|
47671
|
+
yield;
|
|
47475
47672
|
const page = doc.getPage(p - 1);
|
|
47476
47673
|
psLines.push(`%%Page: ${p - firstPage + 1} ${p - firstPage + 1}`);
|
|
47477
47674
|
for (const b of page.extractPage().blocks) {
|
|
47675
|
+
yield;
|
|
47478
47676
|
for (const l of b.lines) {
|
|
47677
|
+
if (++cooperativeWork % 64 === 0)
|
|
47678
|
+
yield;
|
|
47479
47679
|
psLines.push(`${Math.round(l.bbox[0])} ${Math.round(l.bbox[1])} moveto (${l.text}) show`);
|
|
47480
47680
|
}
|
|
47481
47681
|
}
|
|
@@ -47483,13 +47683,14 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47483
47683
|
}
|
|
47484
47684
|
psLines.push("%%Trailer", "%%EOF", "");
|
|
47485
47685
|
const psBytes = new TextEncoder().encode(psLines.join("\n"));
|
|
47486
|
-
if (finalOut === "-")
|
|
47686
|
+
if (finalOut === "-")
|
|
47687
|
+
return { exitCode: 0, stdout: "", stderr: "", stdoutBytes: psBytes };
|
|
47487
47688
|
files.set(finalOut, psBytes);
|
|
47488
47689
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
47489
47690
|
}
|
|
47490
47691
|
const rasterPositionals = positionals.length === 1 && inputPath !== "-" ? [inputPath, inputStem] : positionals;
|
|
47491
47692
|
const snapBefore = new Map(files);
|
|
47492
|
-
const res =
|
|
47693
|
+
const res = yield* runPdftoppmCliSteps([...forwardedArgs, ...rasterPositionals], files, signal);
|
|
47493
47694
|
if (res.exitCode !== 0 || !grayMode && !monoMode) {
|
|
47494
47695
|
return res;
|
|
47495
47696
|
}
|
|
@@ -47508,6 +47709,8 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47508
47709
|
return { ...res, stdoutBytes: encodePng(decoded) };
|
|
47509
47710
|
}
|
|
47510
47711
|
for (const [k, v] of files.entries()) {
|
|
47712
|
+
if (++cooperativeWork % 64 === 0)
|
|
47713
|
+
yield;
|
|
47511
47714
|
if (snapBefore.get(k) !== v && k.endsWith(".png")) {
|
|
47512
47715
|
const decoded = decodePng(v);
|
|
47513
47716
|
convertRgbaInPlace(decoded.data);
|
|
@@ -47516,13 +47719,19 @@ async function runPdftocairoCli(argv, files) {
|
|
|
47516
47719
|
}
|
|
47517
47720
|
return res;
|
|
47518
47721
|
}
|
|
47519
|
-
function
|
|
47722
|
+
async function runPdftocairoCli(argv, files, signal) {
|
|
47723
|
+
return drainSteps(runPdftocairoCliSteps(argv, files, signal), signal);
|
|
47724
|
+
}
|
|
47725
|
+
function createPdftocairoCommand(options = {}) {
|
|
47726
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
47520
47727
|
return Object.freeze({
|
|
47521
47728
|
name: "pdftocairo",
|
|
47522
47729
|
runtimeIdentity: commandRuntimeIdentity,
|
|
47523
47730
|
description: "Render PDF pages to PNG, JPEG, TIFF, PDF, PS, EPS, or SVG via @poe-code/pdf-ast",
|
|
47524
47731
|
execute(context) {
|
|
47525
|
-
return
|
|
47732
|
+
return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
|
|
47733
|
+
return executePopplerFileTool(context2, runPdftocairoCli);
|
|
47734
|
+
});
|
|
47526
47735
|
}
|
|
47527
47736
|
});
|
|
47528
47737
|
}
|