@poe-platform/safe-bash 0.1.789 → 0.1.790
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/image-ast/index.browser.js +147 -80
- package/dist/image-ast/index.js +147 -80
- package/dist/mp4-ast/mp4.d.ts +2 -0
- package/dist/pdf-ast/cos/parser.d.ts +1 -0
- package/dist/pdf-ast/cos/security.d.ts +2 -0
- package/dist/pdf-ast/cos/writer.d.ts +1 -0
- package/dist/pdf-ast/document.d.ts +3 -0
- package/dist/pdf-ast/edit/forms.d.ts +1 -0
- package/dist/pdf-ast/index.js +171 -82
- package/dist/safe-bash/chunks/{chunk-L5QQLNTO.js → chunk-22PI65AH.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-KHJGUF2W.js → chunk-2TAGYMPK.js} +43 -42
- package/dist/safe-bash/chunks/{chunk-D4PHJK4T.js → chunk-2W4HTMEK.js} +52 -48
- package/dist/safe-bash/chunks/{chunk-FFZXP6ZC.js → chunk-3M7L7XU2.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-XNODZRVD.js → chunk-3QAO6UYS.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-YPETOVQU.js → chunk-3VKFK3NF.js} +2 -2
- package/dist/safe-bash/chunks/chunk-5OST7NOX.js +42 -0
- package/dist/safe-bash/chunks/{chunk-KEBSX2AX.js → chunk-6HLURHVU.js} +2 -2
- package/dist/safe-bash/chunks/chunk-DYEUZE6Z.js +19 -0
- package/dist/safe-bash/chunks/{chunk-T2TGCHKE.js → chunk-FM3WBSZT.js} +2 -2
- package/dist/safe-bash/chunks/chunk-GAYRKQM6.js +22 -0
- package/dist/safe-bash/chunks/{chunk-Q45QCA4J.js → chunk-I3KSESCR.js} +0 -7
- package/dist/safe-bash/chunks/{chunk-OSKDIBQS.js → chunk-JLIMK5TD.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-2AYZCT5X.js → chunk-JQ2FAJJT.js} +27 -23
- package/dist/safe-bash/chunks/{chunk-QA3NVP43.js → chunk-JRE6Z3T7.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-DC5EHLKS.js → chunk-NDIL6T7Y.js} +5 -5
- package/dist/safe-bash/chunks/{chunk-747G42FY.js → chunk-OPR4UAIT.js} +2 -2
- package/dist/safe-bash/chunks/chunk-OSMQCYSP.js +19 -0
- package/dist/safe-bash/chunks/chunk-OYB332PQ.js +17 -0
- package/dist/safe-bash/chunks/{chunk-X5ZCECM6.js → chunk-QTIH2AFE.js} +77 -69
- package/dist/safe-bash/chunks/{chunk-CTUHLNJM.js → chunk-SBESXWT2.js} +43 -44
- package/dist/safe-bash/chunks/{chunk-4FDQJUFW.js → chunk-SDEPGTOF.js} +1 -1
- package/dist/safe-bash/chunks/chunk-UZU5BIJI.js +32 -0
- package/dist/safe-bash/chunks/{chunk-BI6JV62X.js → chunk-VCCMROTL.js} +7 -10
- package/dist/safe-bash/chunks/chunk-W47GHRRF.js +13 -0
- package/dist/safe-bash/chunks/{chunk-NPMQWZUZ.js → chunk-WS7KZIUM.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-3PZYHMGM.js → chunk-YYAERCWS.js} +7 -7
- package/dist/safe-bash/chunks/{chunk-5U7JECDB.js → chunk-ZPGVEUKF.js} +8 -7
- package/dist/safe-bash/chunks/{csvkit-K55OYAQC.js → csvkit-USUJG62I.js} +65 -11
- package/dist/safe-bash/chunks/{ffmpeg-BEFTQ6DZ.js → ffmpeg-KRGG5DLH.js} +21 -10
- package/dist/safe-bash/chunks/{gh-HQWOWLWE.js → gh-UCFDUZCX.js} +16 -8
- package/dist/safe-bash/chunks/{git-HO7WDPHZ.js → git-LPAF6KDG.js} +7 -9
- package/dist/safe-bash/chunks/{imagemagick-53BMHH6D.js → imagemagick-KGREKK4G.js} +38 -7
- package/dist/safe-bash/chunks/{implementation-QUTAAYMT.js → implementation-FXDRYS5A.js} +34 -8
- package/dist/safe-bash/chunks/{pdfimages-4OYI6FLG.js → pdfimages-UADCF4G4.js} +12 -8
- package/dist/safe-bash/chunks/{pdfinfo-I7U6TQPP.js → pdfinfo-O7UWPF4W.js} +38 -13
- package/dist/safe-bash/chunks/{pdftk-SUA6FMHI.js → pdftk-AERXIJTN.js} +13 -8
- package/dist/safe-bash/chunks/{pdftoppm-4C5DGEWX.js → pdftoppm-L466JQKI.js} +17 -10
- package/dist/safe-bash/chunks/{pdftotext-Y4WI225Y.js → pdftotext-SUSI4WXS.js} +19 -9
- package/dist/safe-bash/chunks/{qpdf-IORB4RV5.js → qpdf-YL24KVRH.js} +14 -8
- package/dist/safe-bash/chunks/{sips-WHAMJFEU.js → sips-QXEQZERX.js} +14 -7
- package/dist/safe-bash/chunks/{soffice-SYEK6WJS.js → soffice-TBITRML3.js} +16 -8
- package/dist/safe-bash/chunks/{wkhtmltopdf-ZIICWJLF.js → wkhtmltopdf-NJA2THRC.js} +27 -7
- package/dist/safe-bash/command-chunks/chunk-2C5BEBPY.js +1388 -0
- package/dist/safe-bash/command-chunks/{chunk-2VTMZTV3.js → chunk-2EXV2ZLV.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-UJOO6DKY.js → chunk-6EASC5EC.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-ZF3ZVGQC.js → chunk-7JRITHKW.js} +150 -80
- package/dist/safe-bash/{chunks/chunk-LD76P7AG.js → command-chunks/chunk-AKDMCNX4.js} +74 -39
- package/dist/safe-bash/command-chunks/{chunk-6F7QJMJ3.js → chunk-CBDVLMJB.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-H4LWTITX.js +169 -0
- package/dist/safe-bash/command-chunks/chunk-I2MQNBGR.js +145 -0
- package/dist/safe-bash/command-chunks/{chunk-5GRLAARV.js → chunk-IOXI5ZAJ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XNHSCU6I.js → chunk-MDPIOQUD.js} +6 -6
- package/dist/safe-bash/command-chunks/chunk-QI4MGIN6.js +6 -0
- package/dist/safe-bash/command-chunks/chunk-QTYZAWSB.js +91 -0
- package/dist/safe-bash/command-chunks/chunk-SNK7K3XW.js +90 -0
- package/dist/safe-bash/command-chunks/chunk-T5OLGM43.js +314 -0
- package/dist/safe-bash/command-chunks/chunk-TB7IFMUZ.js +802 -0
- package/dist/safe-bash/command-chunks/{chunk-AT6ZSOE6.js → chunk-TPPBPIWL.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-VMK4XVKO.js +82 -0
- package/dist/safe-bash/command-chunks/chunk-VNSJKXDU.js +130 -0
- package/dist/safe-bash/command-chunks/chunk-YFNTMH6Z.js +6 -0
- package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
- package/dist/safe-bash/commands/docx/index.browser.js +2 -2
- package/dist/safe-bash/commands/factor/index.browser.js +2 -2
- package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
- package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
- package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
- package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
- package/dist/safe-bash/commands/llm/command.d.ts +1 -4
- package/dist/safe-bash/commands/llm/command.js +1 -248
- package/dist/safe-bash/commands/llm/elevenlabs-stream.d.ts +1 -2
- package/dist/safe-bash/commands/llm/elevenlabs-stream.js +1 -117
- package/dist/safe-bash/commands/llm/elevenlabs.d.ts +1 -15
- package/dist/safe-bash/commands/llm/elevenlabs.js +1 -123
- package/dist/safe-bash/commands/llm/index.browser.js +20 -15
- package/dist/safe-bash/commands/llm/index.d.ts +1 -6
- package/dist/safe-bash/commands/llm/index.js +1 -4
- package/dist/safe-bash/commands/llm/mime.d.ts +1 -2
- package/dist/safe-bash/commands/llm/mime.js +1 -136
- package/dist/safe-bash/commands/llm/openai-http.d.ts +1 -8
- package/dist/safe-bash/commands/llm/openai-http.js +1 -143
- package/dist/safe-bash/commands/llm/openai-sse.d.ts +1 -3
- package/dist/safe-bash/commands/llm/openai-sse.js +1 -78
- package/dist/safe-bash/commands/llm/openai.d.ts +1 -14
- package/dist/safe-bash/commands/llm/openai.js +1 -288
- package/dist/safe-bash/commands/llm/providers/elevenlabs.d.ts +1 -1
- package/dist/safe-bash/commands/llm/providers/elevenlabs.js +1 -1
- package/dist/safe-bash/commands/llm/providers/index.browser.js +6 -6
- package/dist/safe-bash/commands/llm/providers/index.d.ts +1 -3
- package/dist/safe-bash/commands/llm/providers/index.js +1 -2
- package/dist/safe-bash/commands/llm/providers/openai.d.ts +1 -1
- package/dist/safe-bash/commands/llm/providers/openai.js +1 -1
- package/dist/safe-bash/commands/llm/providers/shared.d.ts +1 -23
- package/dist/safe-bash/commands/llm/providers/shared.js +1 -65
- package/dist/safe-bash/commands/llm/service.d.ts +1 -37
- package/dist/safe-bash/commands/llm/service.js +1 -151
- package/dist/safe-bash/commands/llm/types.d.ts +1 -52
- package/dist/safe-bash/commands/llm/types.js +1 -1
- package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
- package/dist/safe-bash/commands/media/index.browser.js +1 -1
- package/dist/safe-bash/commands/network/index.browser.js +9 -9
- package/dist/safe-bash/commands/network/types.d.ts +2 -40
- package/dist/safe-bash/commands/node/index.browser.js +6 -8
- package/dist/safe-bash/commands/op/index.browser.js +3 -3
- package/dist/safe-bash/commands/op/index.js +12 -28
- package/dist/safe-bash/commands/pr/index.browser.js +2 -2
- package/dist/safe-bash/commands/python/index.browser.js +8 -8
- package/dist/safe-bash/commands/python/worker.browser.js +2 -2
- package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
- package/dist/safe-bash/commands/xml/index.browser.js +2 -2
- package/dist/safe-bash/commands/yq/index.browser.js +3 -3
- package/dist/safe-bash/core.browser.js +9775 -10975
- package/dist/safe-bash/core.d.ts +0 -1
- package/dist/safe-bash/core.js +0 -1
- package/dist/safe-bash/jobs.browser.js +5 -4
- package/dist/safe-bash/optional-host.browser.js +61 -88
- package/dist/safe-bash/shell/runtime.js +34 -12
- package/dist/safe-bash/yq-browser/index.js +1 -1
- package/dist/safe-bash-command-ffmpeg/index.js +8130 -8011
- package/dist/safe-bash-command-git/git_rust.wasm +0 -0
- package/dist/safe-bash-command-git/wasm.generated.js +1 -1
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-llm/LICENSE +21 -0
- package/dist/safe-bash-command-llm/command.d.ts +5 -0
- package/dist/safe-bash-command-llm/command.js +14 -0
- package/dist/safe-bash-command-llm/configuration.d.ts +18 -0
- package/dist/safe-bash-command-llm/elevenlabs-stream.d.ts +2 -0
- package/dist/safe-bash-command-llm/elevenlabs-stream.js +7 -0
- package/dist/safe-bash-command-llm/elevenlabs.d.ts +15 -0
- package/dist/safe-bash-command-llm/elevenlabs.js +10 -0
- package/dist/safe-bash-command-llm/index.d.ts +10 -0
- package/dist/safe-bash-command-llm/index.js +46 -0
- package/dist/safe-bash-command-llm/mime.d.ts +2 -0
- package/dist/safe-bash-command-llm/mime.js +9 -0
- package/dist/safe-bash-command-llm/model-options.d.ts +3 -0
- package/dist/safe-bash-command-llm/openai-http.d.ts +8 -0
- package/dist/safe-bash-command-llm/openai-http.js +17 -0
- package/dist/safe-bash-command-llm/openai-sse.d.ts +3 -0
- package/dist/safe-bash-command-llm/openai-sse.js +8 -0
- package/dist/safe-bash-command-llm/openai.d.ts +14 -0
- package/dist/safe-bash-command-llm/openai.js +12 -0
- package/dist/safe-bash-command-llm/providers/elevenlabs.d.ts +1 -0
- package/dist/safe-bash-command-llm/providers/elevenlabs.js +11 -0
- package/dist/safe-bash-command-llm/providers/index.d.ts +3 -0
- package/dist/safe-bash-command-llm/providers/index.js +24 -0
- package/dist/safe-bash-command-llm/providers/openai.d.ts +1 -0
- package/dist/safe-bash-command-llm/providers/openai.js +13 -0
- package/dist/safe-bash-command-llm/providers/shared.d.ts +23 -0
- package/dist/safe-bash-command-llm/providers/shared.js +13 -0
- package/dist/safe-bash-command-llm/schemas.d.ts +2 -0
- package/dist/safe-bash-command-llm/service.d.ts +42 -0
- package/dist/safe-bash-command-llm/service.js +9 -0
- package/dist/safe-bash-command-llm/templates.d.ts +27 -0
- package/dist/safe-bash-command-llm/types.d.ts +87 -0
- package/dist/safe-bash-command-llm/types.js +6 -0
- package/dist/safe-bash-command-mmdc/command.d.ts +4 -0
- package/dist/safe-bash-command-mmdc/index.d.ts +1 -1
- package/dist/safe-bash-command-mmdc/index.js +7084 -6687
- package/dist/safe-bash-command-mmdc/layout.d.ts +1 -0
- package/dist/safe-bash-command-mmdc/parser.d.ts +1 -0
- package/dist/safe-bash-command-mmdc/png.d.ts +3 -0
- package/dist/safe-bash-command-mmdc/raster.d.ts +1 -0
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +147 -80
- package/dist/safe-bash-command-pdfinfo/index.js +147 -80
- package/dist/safe-bash-command-pdftk/index.js +147 -80
- package/dist/safe-bash-command-pdftoppm/index.js +147 -80
- package/dist/safe-bash-command-pdftotext/index.js +147 -80
- package/dist/safe-bash-command-qpdf/index.js +174 -101
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +1 -1
- package/dist/safe-bash-command-ssconvert/index.js +147 -80
- package/dist/safe-bash-command-wkhtmltopdf/index.js +147 -80
- package/dist/safe-bash-contracts/default-executor.d.ts +5 -0
- package/dist/safe-bash-contracts/default-executor.js +37 -0
- package/dist/safe-bash-contracts/http.d.ts +41 -0
- package/dist/safe-bash-contracts/http.js +6 -0
- 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.d.ts +1 -1
- package/dist/safe-bash-io-engine/gnu-information.js +1 -1
- package/dist/safe-bash-io-engine/internal.js +2 -2
- package/dist/safe-bash-query-engine/index.js +3 -3
- package/dist/safe-bash-query-engine/interpreter.js +2 -2
- package/dist/safe-bash-query-engine/query-core.js +3 -3
- package/package.json +2 -2
- package/dist/safe-bash/chunks/chunk-2G2T5MEM.js +0 -14
- package/dist/safe-bash/chunks/chunk-2MUJ7RLZ.js +0 -409
- package/dist/safe-bash/chunks/chunk-GJWUEOT6.js +0 -14
- package/dist/safe-bash/chunks/chunk-H7MMJS26.js +0 -37
- package/dist/safe-bash/chunks/chunk-LAPF2XE6.js +0 -14
- package/dist/safe-bash/chunks/chunk-S2LSZFZ6.js +0 -758
- package/dist/safe-bash/chunks/chunk-T3VDYWKZ.js +0 -21
- package/dist/safe-bash/chunks/chunk-VUVKC6HV.js +0 -81
- package/dist/safe-bash/chunks/chunk-VYW4Q6KF.js +0 -12
- package/dist/safe-bash/command-chunks/{chunk-BJ6DGYJA.js → chunk-KNI4GRXF.js} +3 -3
|
@@ -30585,6 +30585,14 @@ function parseContentStream(bytes) {
|
|
|
30585
30585
|
// packages/pdf-ast/src/cos/parser.ts
|
|
30586
30586
|
init_buffer();
|
|
30587
30587
|
|
|
30588
|
+
// packages/pdf-ast/src/work.ts
|
|
30589
|
+
init_buffer();
|
|
30590
|
+
function drainWork(work) {
|
|
30591
|
+
let step = work.next();
|
|
30592
|
+
while (!step.done) step = work.next();
|
|
30593
|
+
return step.value;
|
|
30594
|
+
}
|
|
30595
|
+
|
|
30588
30596
|
// packages/pdf-ast/src/cos/security.ts
|
|
30589
30597
|
init_buffer();
|
|
30590
30598
|
|
|
@@ -31186,7 +31194,9 @@ function concatByteArrays(chunks) {
|
|
|
31186
31194
|
}
|
|
31187
31195
|
return out;
|
|
31188
31196
|
}
|
|
31189
|
-
function
|
|
31197
|
+
function* serializeCosDocumentSteps(options) {
|
|
31198
|
+
yield;
|
|
31199
|
+
let work = 0;
|
|
31190
31200
|
const maxOutputBytes = options.maxOutputBytes ?? Infinity;
|
|
31191
31201
|
const maxObjects = options.maxObjects ?? Infinity;
|
|
31192
31202
|
const sorted = [...options.objects].sort((a, b) => a.objectNumber - b.objectNumber);
|
|
@@ -31209,6 +31219,7 @@ function serializeCosDocument(options) {
|
|
|
31209
31219
|
const packable = [];
|
|
31210
31220
|
const direct = [];
|
|
31211
31221
|
for (const obj of sorted) {
|
|
31222
|
+
if (++work % 16 === 0) yield;
|
|
31212
31223
|
const isLinearized = obj.value.kind === "dict" && dictGet(obj.value, "Linearized") !== void 0;
|
|
31213
31224
|
if (obj.value.kind !== "stream" && obj.generationNumber === 0 && !isLinearized) {
|
|
31214
31225
|
packable.push(obj);
|
|
@@ -31223,6 +31234,7 @@ function serializeCosDocument(options) {
|
|
|
31223
31234
|
const headerPairs = [];
|
|
31224
31235
|
let relOffset = 0;
|
|
31225
31236
|
for (const pObj of packable) {
|
|
31237
|
+
if (++work % 16 === 0) yield;
|
|
31226
31238
|
headerPairs.push(`${pObj.objectNumber} ${relOffset}`);
|
|
31227
31239
|
const bBytes = serializeCosNodeBytes(pObj.value);
|
|
31228
31240
|
const nl = textEncoder2.encode("\n");
|
|
@@ -31248,6 +31260,7 @@ function serializeCosDocument(options) {
|
|
|
31248
31260
|
];
|
|
31249
31261
|
const directOffsets = /* @__PURE__ */ new Map();
|
|
31250
31262
|
for (const dObj of allDirect) {
|
|
31263
|
+
if (++work % 16 === 0) yield;
|
|
31251
31264
|
directOffsets.set(dObj.objectNumber, { offset, generation: dObj.generationNumber });
|
|
31252
31265
|
const prefix = textEncoder2.encode(`${dObj.objectNumber} ${dObj.generationNumber} obj
|
|
31253
31266
|
`);
|
|
@@ -31258,6 +31271,7 @@ function serializeCosDocument(options) {
|
|
|
31258
31271
|
}
|
|
31259
31272
|
const compressedMap = /* @__PURE__ */ new Map();
|
|
31260
31273
|
for (let idx = 0; idx < packable.length; idx++) {
|
|
31274
|
+
if (++work % 16 === 0) yield;
|
|
31261
31275
|
compressedMap.set(packable[idx].objectNumber, idx);
|
|
31262
31276
|
}
|
|
31263
31277
|
const xrefOffset2 = offset;
|
|
@@ -31275,6 +31289,7 @@ function serializeCosDocument(options) {
|
|
|
31275
31289
|
};
|
|
31276
31290
|
writeEntry7(0, 0, 0, 65535);
|
|
31277
31291
|
for (let i = 1; i < size2; i++) {
|
|
31292
|
+
if (++work % 16 === 0) yield;
|
|
31278
31293
|
if (i === xrefStmNum) {
|
|
31279
31294
|
writeEntry7(i, 1, xrefOffset2, 0);
|
|
31280
31295
|
} else if (compressedMap.has(i)) {
|
|
@@ -31355,6 +31370,7 @@ ${xrefOffset2}
|
|
|
31355
31370
|
let pageCount = 0;
|
|
31356
31371
|
let firstPageObjNum = options.rootRef.objectNumber;
|
|
31357
31372
|
for (const o of sorted) {
|
|
31373
|
+
if (++work % 16 === 0) yield;
|
|
31358
31374
|
if (o.value.kind === "dict") {
|
|
31359
31375
|
const t = dictGet(o.value, "Type");
|
|
31360
31376
|
if (t?.kind === "name" && t.decoded === "Page") {
|
|
@@ -31402,6 +31418,7 @@ ${xrefOffset2}
|
|
|
31402
31418
|
}
|
|
31403
31419
|
const objectOffsets = /* @__PURE__ */ new Map();
|
|
31404
31420
|
for (const obj of sorted) {
|
|
31421
|
+
if (++work % 16 === 0) yield;
|
|
31405
31422
|
objectOffsets.set(obj.objectNumber, { offset, generation: obj.generationNumber });
|
|
31406
31423
|
let value = obj.value;
|
|
31407
31424
|
if (options.normalizeContent && value.kind === "stream" && value.decodedBytes) {
|
|
@@ -31433,6 +31450,7 @@ ${xrefOffset2}
|
|
|
31433
31450
|
0000000000 65535 f
|
|
31434
31451
|
`;
|
|
31435
31452
|
for (let i = 1; i < size; i++) {
|
|
31453
|
+
if (++work % 16 === 0) yield;
|
|
31436
31454
|
const entry = objectOffsets.get(i);
|
|
31437
31455
|
if (entry) {
|
|
31438
31456
|
xrefText += `${String(entry.offset).padStart(10, "0")} ${String(entry.generation).padStart(5, "0")} n
|
|
@@ -31479,6 +31497,7 @@ ${xrefOffset}
|
|
|
31479
31497
|
let endFirstPage = xrefOffset;
|
|
31480
31498
|
const sortedOffsets = [...objectOffsets.entries()].sort((a, b) => a[1].offset - b[1].offset);
|
|
31481
31499
|
for (let i = 0; i < sortedOffsets.length; i++) {
|
|
31500
|
+
if (++work % 16 === 0) yield;
|
|
31482
31501
|
const [objNum, info3] = sortedOffsets[i];
|
|
31483
31502
|
const nextOff = sortedOffsets[i + 1]?.[1].offset ?? xrefOffset;
|
|
31484
31503
|
if (objNum === hintObjAfter.objectNumber) {
|
|
@@ -31512,6 +31531,9 @@ ${xrefOffset}
|
|
|
31512
31531
|
}
|
|
31513
31532
|
return fullBytes;
|
|
31514
31533
|
}
|
|
31534
|
+
function serializeCosDocument(options) {
|
|
31535
|
+
return drainWork(serializeCosDocumentSteps(options));
|
|
31536
|
+
}
|
|
31515
31537
|
function appendIncrementalRevision(originalBytes, doc, updatedObjects) {
|
|
31516
31538
|
const chunks = [originalBytes, textEncoder2.encode("\n")];
|
|
31517
31539
|
let offset = originalBytes.length + 1;
|
|
@@ -31787,48 +31809,30 @@ function encryptPdfBuffer(state, objectNumber, generationNumber, plaintext) {
|
|
|
31787
31809
|
const objKey = md5Bytes([state.fileKey, suffix]).subarray(0, Math.min(16, state.fileKey.length + 5));
|
|
31788
31810
|
return rc4Transform(objKey, plaintext);
|
|
31789
31811
|
}
|
|
31790
|
-
function
|
|
31812
|
+
function* transformNodeStringsAndStreamsSteps(node, transform, transformStream) {
|
|
31813
|
+
yield;
|
|
31791
31814
|
switch (node.kind) {
|
|
31792
31815
|
case "string":
|
|
31793
|
-
return {
|
|
31794
|
-
|
|
31795
|
-
|
|
31796
|
-
|
|
31797
|
-
};
|
|
31798
|
-
|
|
31799
|
-
return {
|
|
31800
|
-
kind: "array",
|
|
31801
|
-
items: node.items.map((item) => transformNodeStringsAndStreams(item, transform, transformStream))
|
|
31802
|
-
};
|
|
31816
|
+
return { kind: "string", format: "hex", bytes: transform(node.bytes) };
|
|
31817
|
+
case "array": {
|
|
31818
|
+
const items = [];
|
|
31819
|
+
for (const item of node.items) items.push(yield* transformNodeStringsAndStreamsSteps(item, transform, transformStream));
|
|
31820
|
+
return { kind: "array", items };
|
|
31821
|
+
}
|
|
31803
31822
|
case "dict": {
|
|
31804
|
-
const type = dictGet(node, "Type");
|
|
31805
|
-
const fieldType = dictGet(node, "FT");
|
|
31806
|
-
const byteRange = dictGet(node, "ByteRange");
|
|
31823
|
+
const type = dictGet(node, "Type"), fieldType = dictGet(node, "FT"), byteRange = dictGet(node, "ByteRange");
|
|
31807
31824
|
const signature = type?.kind === "name" && type.decoded === "Sig" || fieldType?.kind === "name" && fieldType.decoded === "Sig" || byteRange?.kind === "array" && dictGet(node, "Filter")?.kind === "name";
|
|
31808
|
-
|
|
31809
|
-
|
|
31810
|
-
|
|
31811
|
-
key: e.key,
|
|
31812
|
-
value: signature && e.key.decoded === "Contents" ? e.value : transformNodeStringsAndStreams(e.value, transform, transformStream)
|
|
31813
|
-
}))
|
|
31814
|
-
};
|
|
31825
|
+
const entries = [];
|
|
31826
|
+
for (const e of node.entries) entries.push({ key: e.key, value: signature && e.key.decoded === "Contents" ? e.value : yield* transformNodeStringsAndStreamsSteps(e.value, transform, transformStream) });
|
|
31827
|
+
return { kind: "dict", entries };
|
|
31815
31828
|
}
|
|
31816
31829
|
case "stream": {
|
|
31817
31830
|
const type = dictGet(node.dict, "Type");
|
|
31818
31831
|
if (type?.kind === "name" && type.decoded === "XRef") return node;
|
|
31819
31832
|
const stream = transformStream ? transformStream(node) : { ...node, rawBytes: transform(node.rawBytes) };
|
|
31820
|
-
const
|
|
31821
|
-
|
|
31822
|
-
|
|
31823
|
-
key: e.key,
|
|
31824
|
-
value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : transformNodeStringsAndStreams(e.value, transform, transformStream)
|
|
31825
|
-
}))
|
|
31826
|
-
};
|
|
31827
|
-
return {
|
|
31828
|
-
kind: "stream",
|
|
31829
|
-
dict: updatedDict,
|
|
31830
|
-
rawBytes: stream.rawBytes
|
|
31831
|
-
};
|
|
31833
|
+
const entries = [];
|
|
31834
|
+
for (const e of stream.dict.entries) entries.push({ key: e.key, value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : yield* transformNodeStringsAndStreamsSteps(e.value, transform, transformStream) });
|
|
31835
|
+
return { kind: "stream", dict: { kind: "dict", entries }, rawBytes: stream.rawBytes };
|
|
31832
31836
|
}
|
|
31833
31837
|
default:
|
|
31834
31838
|
return node;
|
|
@@ -31897,7 +31901,8 @@ function createR6Encryption(userPassword, ownerPassword, pMask) {
|
|
|
31897
31901
|
StrF: cosName("StdCF")
|
|
31898
31902
|
}) };
|
|
31899
31903
|
}
|
|
31900
|
-
function
|
|
31904
|
+
function* encryptCosDocumentSteps(doc, options = {}) {
|
|
31905
|
+
yield;
|
|
31901
31906
|
const userPassword = options.userPassword ?? "";
|
|
31902
31907
|
const ownerPassword = options.ownerPassword ?? userPassword;
|
|
31903
31908
|
const revision = options.revision ?? 6;
|
|
@@ -31919,14 +31924,15 @@ function encryptCosDocument(doc, options = {}) {
|
|
|
31919
31924
|
const encryptObjNum = maxObjNum + 1;
|
|
31920
31925
|
const encryptedObjects = [];
|
|
31921
31926
|
for (const obj of doc.objects.values()) {
|
|
31922
|
-
|
|
31927
|
+
yield;
|
|
31928
|
+
const transformed = yield* transformNodeStringsAndStreamsSteps(
|
|
31923
31929
|
obj.value,
|
|
31924
31930
|
(plain) => encryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, plain)
|
|
31925
31931
|
);
|
|
31926
31932
|
encryptedObjects.push({ objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: transformed });
|
|
31927
31933
|
}
|
|
31928
31934
|
encryptedObjects.push({ objectNumber: encryptObjNum, generationNumber: 0, value: encryptDict });
|
|
31929
|
-
return
|
|
31935
|
+
return yield* serializeCosDocumentSteps({
|
|
31930
31936
|
objects: encryptedObjects,
|
|
31931
31937
|
rootRef: doc.rootRef,
|
|
31932
31938
|
infoRef: doc.infoRef,
|
|
@@ -31976,17 +31982,19 @@ function decryptStream(doc, stream, transform) {
|
|
|
31976
31982
|
}
|
|
31977
31983
|
return { kind: "stream", dict, rawBytes: bytes };
|
|
31978
31984
|
}
|
|
31979
|
-
function
|
|
31985
|
+
function* decryptCosDocumentSteps(doc, state) {
|
|
31986
|
+
yield;
|
|
31980
31987
|
const encryptObjNum = doc.encryptRef?.objectNumber;
|
|
31981
31988
|
const handler = securityHandlers.get(state);
|
|
31982
31989
|
for (const [num, obj] of doc.objects.entries()) {
|
|
31990
|
+
yield;
|
|
31983
31991
|
if (num === encryptObjNum || handler?.plaintextObjects.has(num)) continue;
|
|
31984
31992
|
if (obj.value.kind === "stream") {
|
|
31985
31993
|
const type = doc.resolve(dictGet(obj.value.dict, "Type"));
|
|
31986
31994
|
if (type?.kind === "name" && (type.decoded === "XRef" || type.decoded === "Metadata" && !state.encryptMetadata)) continue;
|
|
31987
31995
|
}
|
|
31988
31996
|
const transform = handler?.factory.createCipherTransform(obj.objectNumber, obj.generationNumber);
|
|
31989
|
-
const decrypted =
|
|
31997
|
+
const decrypted = yield* transformNodeStringsAndStreamsSteps(
|
|
31990
31998
|
obj.value,
|
|
31991
31999
|
(cipher) => decryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, cipher),
|
|
31992
32000
|
transform ? (stream) => decryptStream(doc, stream, transform) : void 0
|
|
@@ -32102,9 +32110,12 @@ var ParsedCosDocument = class {
|
|
|
32102
32110
|
return void 0;
|
|
32103
32111
|
}
|
|
32104
32112
|
};
|
|
32105
|
-
function
|
|
32113
|
+
function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
|
|
32114
|
+
yield;
|
|
32115
|
+
let work = 0;
|
|
32106
32116
|
const stack = [];
|
|
32107
32117
|
while (true) {
|
|
32118
|
+
if (++work % 16 === 0) yield;
|
|
32108
32119
|
const tok = lexer.nextToken();
|
|
32109
32120
|
const parent = stack.at(-1);
|
|
32110
32121
|
if (!tok) {
|
|
@@ -32300,7 +32311,8 @@ function parseHeaderVersion(bytes) {
|
|
|
32300
32311
|
}
|
|
32301
32312
|
return head.slice(idx + 5, idx + 8);
|
|
32302
32313
|
}
|
|
32303
|
-
function
|
|
32314
|
+
function* parseObjectAtOffsetSteps(bytes, offset, maxRecursionDepth, repair = false) {
|
|
32315
|
+
yield;
|
|
32304
32316
|
const lexer = new CosByteLexer(bytes, offset);
|
|
32305
32317
|
const objNumTok = lexer.nextToken();
|
|
32306
32318
|
const genNumTok = lexer.nextToken();
|
|
@@ -32308,7 +32320,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
|
|
|
32308
32320
|
if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
|
|
32309
32321
|
throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
|
|
32310
32322
|
}
|
|
32311
|
-
const value =
|
|
32323
|
+
const value = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, repair);
|
|
32312
32324
|
if (!value) {
|
|
32313
32325
|
throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
|
|
32314
32326
|
}
|
|
@@ -32319,7 +32331,9 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
|
|
|
32319
32331
|
span: { start: objNumTok.span.start, end: lexer.offset }
|
|
32320
32332
|
};
|
|
32321
32333
|
}
|
|
32322
|
-
function
|
|
32334
|
+
function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
|
|
32335
|
+
yield;
|
|
32336
|
+
let work = 0;
|
|
32323
32337
|
if (xrefOffset < 0 || xrefOffset >= bytes.length) {
|
|
32324
32338
|
throw new PdfError("E_PARSE", `Invalid xref offset: ${xrefOffset}`);
|
|
32325
32339
|
}
|
|
@@ -32331,6 +32345,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
32331
32345
|
if (firstTok.kind === "keyword" && firstTok.value === "xref") {
|
|
32332
32346
|
const entries2 = /* @__PURE__ */ new Map();
|
|
32333
32347
|
while (true) {
|
|
32348
|
+
if (++work % 16 === 0) yield;
|
|
32334
32349
|
const saved = lexer.offset;
|
|
32335
32350
|
const tok = lexer.nextToken();
|
|
32336
32351
|
if (!tok) {
|
|
@@ -32354,6 +32369,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
32354
32369
|
}
|
|
32355
32370
|
if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
32356
32371
|
for (let i = 0; i < count; i++) {
|
|
32372
|
+
if (++work % 16 === 0) yield;
|
|
32357
32373
|
const offTok = lexer.nextToken();
|
|
32358
32374
|
const genTok = lexer.nextToken();
|
|
32359
32375
|
const flagTok = lexer.nextToken();
|
|
@@ -32379,7 +32395,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
32379
32395
|
if (entries2.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
32380
32396
|
}
|
|
32381
32397
|
}
|
|
32382
|
-
const trailerNode =
|
|
32398
|
+
const trailerNode = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth);
|
|
32383
32399
|
if (!trailerNode || trailerNode.kind !== "dict") {
|
|
32384
32400
|
throw new PdfError("E_PARSE", "Missing trailer dictionary after xref table");
|
|
32385
32401
|
}
|
|
@@ -32391,7 +32407,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
32391
32407
|
previousXrefOffset: prevNode2?.kind === "number" ? prevNode2.value : void 0
|
|
32392
32408
|
};
|
|
32393
32409
|
}
|
|
32394
|
-
const xrefObj =
|
|
32410
|
+
const xrefObj = yield* parseObjectAtOffsetSteps(bytes, xrefOffset, maxRecursionDepth);
|
|
32395
32411
|
if (xrefObj.value.kind !== "stream") {
|
|
32396
32412
|
throw new PdfError("E_PARSE", `Expected xref table or XRef stream at offset ${xrefOffset}`);
|
|
32397
32413
|
}
|
|
@@ -32412,6 +32428,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
32412
32428
|
if (indexArray) {
|
|
32413
32429
|
if (indexArray.kind !== "array" || indexArray.items.length % 2 !== 0) throw new PdfError("E_PARSE", "Invalid XRef range fields");
|
|
32414
32430
|
for (let i = 0; i < indexArray.items.length; i += 2) {
|
|
32431
|
+
if (++work % 16 === 0) yield;
|
|
32415
32432
|
const first = indexArray.items[i];
|
|
32416
32433
|
const count = indexArray.items[i + 1];
|
|
32417
32434
|
if (first?.kind !== "number" || count?.kind !== "number" || !Number.isSafeInteger(first.value) || first.value < 0 || !Number.isSafeInteger(count.value) || count.value < 0 || !Number.isSafeInteger(first.value + count.value)) {
|
|
@@ -32434,9 +32451,11 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
32434
32451
|
return v;
|
|
32435
32452
|
};
|
|
32436
32453
|
for (const [startObj, count] of subsections) {
|
|
32454
|
+
if (++work % 16 === 0) yield;
|
|
32437
32455
|
if (count > (decoded.length - pos) / stride) throw new PdfError("E_PARSE", "Truncated XRef stream");
|
|
32438
32456
|
if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
32439
32457
|
for (let i = 0; i < count; i++) {
|
|
32458
|
+
if (++work % 16 === 0) yield;
|
|
32440
32459
|
const objNum = startObj + i;
|
|
32441
32460
|
const field0 = w0 > 0 ? readInt(w0) : 1;
|
|
32442
32461
|
const field1 = readInt(w1);
|
|
@@ -32482,12 +32501,16 @@ function isAsciiWhitespace(ch3) {
|
|
|
32482
32501
|
function isAsciiDigit2(ch3) {
|
|
32483
32502
|
return ch3 >= 48 && ch3 <= 57;
|
|
32484
32503
|
}
|
|
32485
|
-
function
|
|
32504
|
+
function* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth) {
|
|
32505
|
+
yield;
|
|
32506
|
+
let work = 0;
|
|
32486
32507
|
const objects = /* @__PURE__ */ new Map();
|
|
32487
32508
|
const trailers = [];
|
|
32488
32509
|
let pos = 0;
|
|
32489
32510
|
while (pos < bytes.length) {
|
|
32511
|
+
if (++work % 16 === 0) yield;
|
|
32490
32512
|
while (pos < bytes.length && !isAsciiDigit2(bytes[pos])) {
|
|
32513
|
+
if (++work % 16 === 0) yield;
|
|
32491
32514
|
if (bytes[pos] === 37) {
|
|
32492
32515
|
while (pos < bytes.length && bytes[pos] !== 10 && bytes[pos] !== 13) pos++;
|
|
32493
32516
|
continue;
|
|
@@ -32497,7 +32520,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
32497
32520
|
try {
|
|
32498
32521
|
const token = lexer.nextToken();
|
|
32499
32522
|
if (token?.kind === "keyword" && token.value === "trailer") {
|
|
32500
|
-
const trailer =
|
|
32523
|
+
const trailer = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, true);
|
|
32501
32524
|
if (trailer?.kind === "dict") trailers.push(trailer);
|
|
32502
32525
|
pos = lexer.offset;
|
|
32503
32526
|
continue;
|
|
@@ -32530,7 +32553,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
32530
32553
|
bytes[pos + 3] === 40)) {
|
|
32531
32554
|
pos += 3;
|
|
32532
32555
|
try {
|
|
32533
|
-
const parsed =
|
|
32556
|
+
const parsed = yield* parseObjectAtOffsetSteps(bytes, headerStart, maxRecursionDepth, true);
|
|
32534
32557
|
objects.set(parsed.objectNumber, parsed);
|
|
32535
32558
|
if (parsed.value.kind === "stream") {
|
|
32536
32559
|
const type = dictGet(parsed.value.dict, "Type");
|
|
@@ -32547,13 +32570,17 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
32547
32570
|
}
|
|
32548
32571
|
return { objects, trailers };
|
|
32549
32572
|
}
|
|
32550
|
-
function
|
|
32573
|
+
function* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
|
|
32574
|
+
yield;
|
|
32575
|
+
let work = 0;
|
|
32551
32576
|
for (const obj of [...objects.values()]) {
|
|
32577
|
+
if (++work % 16 === 0) yield;
|
|
32552
32578
|
if (obj.value.kind === "stream") {
|
|
32553
32579
|
const t = dictGet(obj.value.dict, "Type");
|
|
32554
32580
|
if (t?.kind === "name" && t.decoded === "ObjStm") {
|
|
32555
32581
|
try {
|
|
32556
|
-
for (const [unpackedNum, unpackedVal] of
|
|
32582
|
+
for (const [unpackedNum, unpackedVal] of (yield* unpackObjectStreamSteps(obj.value, maxDecompressedBytes, maxRecursionDepth, true)).entries()) {
|
|
32583
|
+
if (++work % 16 === 0) yield;
|
|
32557
32584
|
if (!objects.has(unpackedNum)) {
|
|
32558
32585
|
objects.set(unpackedNum, {
|
|
32559
32586
|
objectNumber: unpackedNum,
|
|
@@ -32589,7 +32616,9 @@ function recoveredReferences(objects) {
|
|
|
32589
32616
|
}
|
|
32590
32617
|
return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
|
|
32591
32618
|
}
|
|
32592
|
-
function
|
|
32619
|
+
function* unpackObjectStreamSteps(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
|
|
32620
|
+
yield;
|
|
32621
|
+
let work = 0;
|
|
32593
32622
|
const nNode = dictGet(streamObj.dict, "N");
|
|
32594
32623
|
const firstNode = dictGet(streamObj.dict, "First");
|
|
32595
32624
|
if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
|
|
@@ -32599,6 +32628,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
32599
32628
|
const headerLexer = new CosByteLexer(decoded, 0);
|
|
32600
32629
|
const pairs = [];
|
|
32601
32630
|
for (let i = 0; i < nNode.value; i++) {
|
|
32631
|
+
if (++work % 16 === 0) yield;
|
|
32602
32632
|
const numTok = headerLexer.nextToken();
|
|
32603
32633
|
const offTok = headerLexer.nextToken();
|
|
32604
32634
|
if (numTok?.kind === "number" && offTok?.kind === "number") {
|
|
@@ -32607,9 +32637,10 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
32607
32637
|
}
|
|
32608
32638
|
const result = /* @__PURE__ */ new Map();
|
|
32609
32639
|
for (const pair of pairs) {
|
|
32640
|
+
if (++work % 16 === 0) yield;
|
|
32610
32641
|
try {
|
|
32611
32642
|
const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
|
|
32612
|
-
const node =
|
|
32643
|
+
const node = yield* parseNodeFromLexerSteps(valLexer, decoded, maxRecursionDepth, repair);
|
|
32613
32644
|
if (node) {
|
|
32614
32645
|
result.set(pair.objectNumber, node);
|
|
32615
32646
|
}
|
|
@@ -32619,7 +32650,9 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
32619
32650
|
}
|
|
32620
32651
|
return result;
|
|
32621
32652
|
}
|
|
32622
|
-
function
|
|
32653
|
+
function* parseCosDocumentSteps(bytes, options = {}) {
|
|
32654
|
+
yield;
|
|
32655
|
+
let work = 0;
|
|
32623
32656
|
const version = parseHeaderVersion(bytes);
|
|
32624
32657
|
const recovery = options.recovery ?? "strict";
|
|
32625
32658
|
const maxObjects = options.maxObjects ?? Infinity;
|
|
@@ -32654,10 +32687,12 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
32654
32687
|
let currentXrefOffset = offsetTok.value;
|
|
32655
32688
|
const visitedOffsets = /* @__PURE__ */ new Set();
|
|
32656
32689
|
while (currentXrefOffset !== void 0 && !visitedOffsets.has(currentXrefOffset)) {
|
|
32690
|
+
if (++work % 16 === 0) yield;
|
|
32657
32691
|
visitedOffsets.add(currentXrefOffset);
|
|
32658
|
-
const rev =
|
|
32692
|
+
const rev = yield* parseXrefRevisionAtSteps(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
|
|
32659
32693
|
revisions.push(rev);
|
|
32660
32694
|
for (const [num, entry] of rev.entries.entries()) {
|
|
32695
|
+
if (++work % 16 === 0) yield;
|
|
32661
32696
|
if (!mergedXref.has(num)) {
|
|
32662
32697
|
mergedXref.set(num, entry);
|
|
32663
32698
|
if (mergedXref.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
@@ -32690,8 +32725,9 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
32690
32725
|
if (!useRepair && rootRef) {
|
|
32691
32726
|
try {
|
|
32692
32727
|
for (const [objNum, entry] of mergedXref.entries()) {
|
|
32728
|
+
if (++work % 16 === 0) yield;
|
|
32693
32729
|
if (entry.type !== "uncompressed") continue;
|
|
32694
|
-
const parsed =
|
|
32730
|
+
const parsed = yield* parseObjectAtOffsetSteps(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
|
|
32695
32731
|
if (parsed.objectNumber !== objNum || parsed.generationNumber !== (entry.generationNumber ?? 0)) {
|
|
32696
32732
|
throw new PdfError("E_PARSE", `Bad uncompressed XRef entry for object ${objNum}`);
|
|
32697
32733
|
}
|
|
@@ -32709,7 +32745,7 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
32709
32745
|
throw new PdfError("E_PARSE", "PDF trailer missing /Root reference");
|
|
32710
32746
|
}
|
|
32711
32747
|
useRepair = true;
|
|
32712
|
-
const scanned =
|
|
32748
|
+
const scanned = yield* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth);
|
|
32713
32749
|
objects = scanned.objects;
|
|
32714
32750
|
revisions.length = 0;
|
|
32715
32751
|
mergedXref.clear();
|
|
@@ -32744,7 +32780,7 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
32744
32780
|
encryptNode = encrypt?.kind === "ref" || encrypt?.kind === "dict" ? encrypt : void 0;
|
|
32745
32781
|
encryptRef = encrypt?.kind === "ref" ? encrypt : void 0;
|
|
32746
32782
|
idArray = id?.kind === "array" ? id : void 0;
|
|
32747
|
-
if (!rootRef && !encryptNode)
|
|
32783
|
+
if (!rootRef && !encryptNode) yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
|
|
32748
32784
|
const fallback = recoveredReferences(objects);
|
|
32749
32785
|
rootRef ??= fallback.rootRef;
|
|
32750
32786
|
infoRef ??= fallback.infoRef;
|
|
@@ -32779,20 +32815,21 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
32779
32815
|
maxRecursionDepth
|
|
32780
32816
|
});
|
|
32781
32817
|
doc.encryption = encState;
|
|
32782
|
-
|
|
32818
|
+
yield* decryptCosDocumentSteps(doc, encState);
|
|
32783
32819
|
}
|
|
32784
32820
|
if (useRepair) {
|
|
32785
|
-
|
|
32821
|
+
yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
|
|
32786
32822
|
doc.infoRef ??= recoveredReferences(objects).infoRef;
|
|
32787
32823
|
}
|
|
32788
32824
|
const objStmCache = /* @__PURE__ */ new Map();
|
|
32789
32825
|
for (const [objNum, entry] of mergedXref.entries()) {
|
|
32826
|
+
if (++work % 16 === 0) yield;
|
|
32790
32827
|
if (entry.type === "compressed" && entry.objectStreamNumber !== void 0) {
|
|
32791
32828
|
let unpacked = objStmCache.get(entry.objectStreamNumber);
|
|
32792
32829
|
if (!unpacked) {
|
|
32793
32830
|
const stmObj = objects.get(entry.objectStreamNumber)?.value;
|
|
32794
32831
|
if (stmObj?.kind === "stream") {
|
|
32795
|
-
unpacked =
|
|
32832
|
+
unpacked = yield* unpackObjectStreamSteps(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
|
|
32796
32833
|
objStmCache.set(entry.objectStreamNumber, unpacked);
|
|
32797
32834
|
}
|
|
32798
32835
|
}
|
|
@@ -32809,6 +32846,9 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
32809
32846
|
}
|
|
32810
32847
|
return doc;
|
|
32811
32848
|
}
|
|
32849
|
+
function parseCosDocument(bytes, options = {}) {
|
|
32850
|
+
return drainWork(parseCosDocumentSteps(bytes, options));
|
|
32851
|
+
}
|
|
32812
32852
|
|
|
32813
32853
|
// packages/pdf-ast/src/extract/images.ts
|
|
32814
32854
|
var cmykColorSpace = new DeviceCmykCS();
|
|
@@ -39282,7 +39322,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
|
|
|
39282
39322
|
}
|
|
39283
39323
|
return void 0;
|
|
39284
39324
|
}
|
|
39285
|
-
function
|
|
39325
|
+
function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
|
|
39326
|
+
if (++yieldState.work % 256 === 0) yield;
|
|
39286
39327
|
const dict = doc.resolveDict(node);
|
|
39287
39328
|
if (!dict) return out;
|
|
39288
39329
|
const tNode = doc.resolve(dictGet(dict, "T"));
|
|
@@ -39315,7 +39356,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
|
|
|
39315
39356
|
return out;
|
|
39316
39357
|
}
|
|
39317
39358
|
for (const kid of kidsArr.items) {
|
|
39318
|
-
|
|
39359
|
+
if (++yieldState.work % 16 === 0) yield;
|
|
39360
|
+
yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
|
|
39319
39361
|
}
|
|
39320
39362
|
} else if (fullName) {
|
|
39321
39363
|
out.push({
|
|
@@ -39756,6 +39798,9 @@ function escapePdfLiteralString(str) {
|
|
|
39756
39798
|
}
|
|
39757
39799
|
return out;
|
|
39758
39800
|
}
|
|
39801
|
+
function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
|
|
39802
|
+
drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
|
|
39803
|
+
}
|
|
39759
39804
|
|
|
39760
39805
|
// packages/pdf-ast/src/edit/resources.ts
|
|
39761
39806
|
init_buffer();
|
|
@@ -40001,14 +40046,18 @@ var PdfDocument = class _PdfDocument {
|
|
|
40001
40046
|
});
|
|
40002
40047
|
return new _PdfDocument(parseCosDocument(rawBytes));
|
|
40003
40048
|
}
|
|
40004
|
-
static
|
|
40049
|
+
static *loadSteps(bytes, options) {
|
|
40050
|
+
yield;
|
|
40005
40051
|
return new _PdfDocument(
|
|
40006
|
-
|
|
40052
|
+
yield* parseCosDocumentSteps(bytes, {
|
|
40007
40053
|
...options,
|
|
40008
40054
|
recovery: options?.recovery ?? "repair"
|
|
40009
40055
|
})
|
|
40010
40056
|
);
|
|
40011
40057
|
}
|
|
40058
|
+
static load(bytes, options) {
|
|
40059
|
+
return drainWork(_PdfDocument.loadSteps(bytes, options));
|
|
40060
|
+
}
|
|
40012
40061
|
rebuildPagesList() {
|
|
40013
40062
|
const catalog = this.cos.resolveDict(this.cos.rootRef);
|
|
40014
40063
|
const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
|
|
@@ -40090,20 +40139,30 @@ var PdfDocument = class _PdfDocument {
|
|
|
40090
40139
|
this.pages.splice(index, 1);
|
|
40091
40140
|
this.syncPageTree();
|
|
40092
40141
|
}
|
|
40093
|
-
|
|
40142
|
+
*copyPagesFromSteps(sourceDoc, indices) {
|
|
40143
|
+
function* cloneItems(items) {
|
|
40144
|
+
const result = [];
|
|
40145
|
+
for (const item of items) result.push(yield* cloneNode(item));
|
|
40146
|
+
return result;
|
|
40147
|
+
}
|
|
40148
|
+
yield;
|
|
40149
|
+
let work = 0;
|
|
40094
40150
|
const memo = /* @__PURE__ */ new Map();
|
|
40095
40151
|
const sourcePageObjNums = /* @__PURE__ */ new Set();
|
|
40096
40152
|
for (let i = 0; i < sourceDoc.getPageCount(); i++) {
|
|
40153
|
+
if (++work % 16 === 0) yield;
|
|
40097
40154
|
sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
|
|
40098
40155
|
}
|
|
40099
40156
|
const targetPageRefs = [];
|
|
40100
40157
|
for (const idx of indices) {
|
|
40158
|
+
if (++work % 16 === 0) yield;
|
|
40101
40159
|
const srcPage = sourceDoc.getPage(idx);
|
|
40102
40160
|
const pageRef = this.cos.allocateObject({ kind: "null" });
|
|
40103
40161
|
targetPageRefs.push(pageRef);
|
|
40104
40162
|
memo.set(srcPage.ref.objectNumber, pageRef);
|
|
40105
40163
|
}
|
|
40106
|
-
const cloneNode = (node)
|
|
40164
|
+
const cloneNode = function* (node) {
|
|
40165
|
+
if (++work % 16 === 0) yield;
|
|
40107
40166
|
if (node.kind === "ref") {
|
|
40108
40167
|
const existing = memo.get(node.objectNumber);
|
|
40109
40168
|
if (existing) return existing;
|
|
@@ -40114,12 +40173,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
40114
40173
|
if (!target) return cosRef(0);
|
|
40115
40174
|
const placeholderRef = this.cos.allocateObject({ kind: "null" });
|
|
40116
40175
|
memo.set(node.objectNumber, placeholderRef);
|
|
40117
|
-
const clonedTarget = cloneNode(target);
|
|
40176
|
+
const clonedTarget = yield* cloneNode(target);
|
|
40118
40177
|
this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
|
|
40119
40178
|
return placeholderRef;
|
|
40120
40179
|
}
|
|
40121
40180
|
if (node.kind === "array") {
|
|
40122
|
-
return cosArray(node.items
|
|
40181
|
+
return cosArray(yield* cloneItems(node.items));
|
|
40123
40182
|
}
|
|
40124
40183
|
if (node.kind === "dict") {
|
|
40125
40184
|
const typeEntry = dictGet(node, "Type");
|
|
@@ -40129,13 +40188,13 @@ var PdfDocument = class _PdfDocument {
|
|
|
40129
40188
|
if (isPageTreeNode && entry.key.decoded === "Parent") continue;
|
|
40130
40189
|
newEntries.push({
|
|
40131
40190
|
key: { ...entry.key },
|
|
40132
|
-
value: cloneNode(entry.value)
|
|
40191
|
+
value: yield* cloneNode(entry.value)
|
|
40133
40192
|
});
|
|
40134
40193
|
}
|
|
40135
40194
|
return { kind: "dict", entries: newEntries };
|
|
40136
40195
|
}
|
|
40137
40196
|
if (node.kind === "stream") {
|
|
40138
|
-
const clonedDict = cloneNode(node.dict);
|
|
40197
|
+
const clonedDict = yield* cloneNode(node.dict);
|
|
40139
40198
|
return {
|
|
40140
40199
|
kind: "stream",
|
|
40141
40200
|
dict: clonedDict,
|
|
@@ -40144,11 +40203,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
40144
40203
|
};
|
|
40145
40204
|
}
|
|
40146
40205
|
return node;
|
|
40147
|
-
};
|
|
40206
|
+
}.bind(this);
|
|
40148
40207
|
const copiedPages = [];
|
|
40149
40208
|
for (const [position, idx] of indices.entries()) {
|
|
40209
|
+
if (++work % 16 === 0) yield;
|
|
40150
40210
|
const srcPage = sourceDoc.getPage(idx);
|
|
40151
|
-
const clonedPageDict = cloneNode(srcPage.pageDict);
|
|
40211
|
+
const clonedPageDict = yield* cloneNode(srcPage.pageDict);
|
|
40152
40212
|
const size = srcPage.getSize();
|
|
40153
40213
|
if (!dictGet(clonedPageDict, "MediaBox")) {
|
|
40154
40214
|
dictSet(
|
|
@@ -40158,13 +40218,14 @@ var PdfDocument = class _PdfDocument {
|
|
|
40158
40218
|
);
|
|
40159
40219
|
}
|
|
40160
40220
|
if (!dictGet(clonedPageDict, "Resources")) {
|
|
40161
|
-
dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
|
|
40221
|
+
dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
|
|
40162
40222
|
}
|
|
40163
40223
|
if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
|
|
40164
40224
|
dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
|
|
40165
40225
|
}
|
|
40166
40226
|
const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
|
|
40167
40227
|
for (const boxKey of inheritedBoxKeys) {
|
|
40228
|
+
if (++work % 16 === 0) yield;
|
|
40168
40229
|
if (!dictGet(clonedPageDict, boxKey)) {
|
|
40169
40230
|
const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
|
|
40170
40231
|
if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
|
|
@@ -40206,8 +40267,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
40206
40267
|
};
|
|
40207
40268
|
const clonedRootFieldRefs = [];
|
|
40208
40269
|
for (const item of srcFieldsArr.items) {
|
|
40270
|
+
if (++work % 16 === 0) yield;
|
|
40209
40271
|
if (!hasClonedDescendant(item)) continue;
|
|
40210
|
-
const cloned = cloneNode(item);
|
|
40272
|
+
const cloned = yield* cloneNode(item);
|
|
40211
40273
|
if (cloned.kind === "ref") {
|
|
40212
40274
|
const clonedDict = this.cos.resolveDict(cloned);
|
|
40213
40275
|
const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
|
|
@@ -40241,6 +40303,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
40241
40303
|
dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
|
|
40242
40304
|
);
|
|
40243
40305
|
for (const fRef of clonedRootFieldRefs) {
|
|
40306
|
+
if (++work % 16 === 0) yield;
|
|
40244
40307
|
if (!existingNums.has(fRef.objectNumber)) {
|
|
40245
40308
|
dstFields.items.push(fRef);
|
|
40246
40309
|
existingNums.add(fRef.objectNumber);
|
|
@@ -40248,11 +40311,11 @@ var PdfDocument = class _PdfDocument {
|
|
|
40248
40311
|
}
|
|
40249
40312
|
const srcDr = dictGet(srcAcroForm, "DR");
|
|
40250
40313
|
if (srcDr && !dictGet(dstAcroForm, "DR")) {
|
|
40251
|
-
dictSet(dstAcroForm, "DR", cloneNode(srcDr));
|
|
40314
|
+
dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
|
|
40252
40315
|
}
|
|
40253
40316
|
const srcDa = dictGet(srcAcroForm, "DA");
|
|
40254
40317
|
if (srcDa && !dictGet(dstAcroForm, "DA")) {
|
|
40255
|
-
dictSet(dstAcroForm, "DA", cloneNode(srcDa));
|
|
40318
|
+
dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
|
|
40256
40319
|
}
|
|
40257
40320
|
}
|
|
40258
40321
|
}
|
|
@@ -40261,12 +40324,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
40261
40324
|
if (srcOcProps) {
|
|
40262
40325
|
const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
|
|
40263
40326
|
if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
|
|
40264
|
-
dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
|
|
40327
|
+
dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
|
|
40265
40328
|
}
|
|
40266
40329
|
}
|
|
40267
40330
|
this.syncPageTree();
|
|
40268
40331
|
return copiedPages;
|
|
40269
40332
|
}
|
|
40333
|
+
copyPagesFrom(sourceDoc, indices) {
|
|
40334
|
+
return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
|
|
40335
|
+
}
|
|
40270
40336
|
embedStandardFont(fontName) {
|
|
40271
40337
|
return createStandardFontHandle(fontName);
|
|
40272
40338
|
}
|
|
@@ -40466,14 +40532,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
40466
40532
|
});
|
|
40467
40533
|
return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
|
|
40468
40534
|
}
|
|
40469
|
-
|
|
40535
|
+
*saveSteps(options = {}) {
|
|
40536
|
+
yield;
|
|
40470
40537
|
this.syncPageTree();
|
|
40471
40538
|
if (this.cos.requiresFullRewrite) {
|
|
40472
40539
|
pruneUnusedXObjects(this.cos, this.pages);
|
|
40473
40540
|
discardUnreachableObjects(this.cos);
|
|
40474
40541
|
}
|
|
40475
40542
|
if (options.encrypt) {
|
|
40476
|
-
return
|
|
40543
|
+
return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
|
|
40477
40544
|
}
|
|
40478
40545
|
const allObjects = [...this.cos.objects.values()].sort(
|
|
40479
40546
|
(a, b) => a.objectNumber - b.objectNumber
|
|
@@ -40481,7 +40548,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
40481
40548
|
if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
|
|
40482
40549
|
return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
|
|
40483
40550
|
}
|
|
40484
|
-
return
|
|
40551
|
+
return yield* serializeCosDocumentSteps({
|
|
40485
40552
|
objects: allObjects,
|
|
40486
40553
|
rootRef: this.cos.rootRef,
|
|
40487
40554
|
infoRef: this.cos.infoRef,
|
|
@@ -40492,6 +40559,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
40492
40559
|
linearize: options.linearize
|
|
40493
40560
|
});
|
|
40494
40561
|
}
|
|
40562
|
+
save(options = {}) {
|
|
40563
|
+
return drainWork(this.saveSteps(options));
|
|
40564
|
+
}
|
|
40495
40565
|
};
|
|
40496
40566
|
|
|
40497
40567
|
// packages/pdf-ast/src/index.ts
|