@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
|
@@ -27296,6 +27296,11 @@ function tokenizeCos(bytes, start = 0, end = bytes.length) {
|
|
|
27296
27296
|
}
|
|
27297
27297
|
return tokens;
|
|
27298
27298
|
}
|
|
27299
|
+
function drainWork(work) {
|
|
27300
|
+
let step = work.next();
|
|
27301
|
+
while (!step.done) step = work.next();
|
|
27302
|
+
return step.value;
|
|
27303
|
+
}
|
|
27299
27304
|
function bytesToString3(bytes) {
|
|
27300
27305
|
if (typeof bytes !== "object" || bytes?.length === void 0) {
|
|
27301
27306
|
throw new Error("Invalid argument for bytesToString");
|
|
@@ -27891,7 +27896,9 @@ function concatByteArrays(chunks) {
|
|
|
27891
27896
|
}
|
|
27892
27897
|
return out;
|
|
27893
27898
|
}
|
|
27894
|
-
function
|
|
27899
|
+
function* serializeCosDocumentSteps(options) {
|
|
27900
|
+
yield;
|
|
27901
|
+
let work = 0;
|
|
27895
27902
|
const maxOutputBytes = options.maxOutputBytes ?? Infinity;
|
|
27896
27903
|
const maxObjects = options.maxObjects ?? Infinity;
|
|
27897
27904
|
const sorted = [...options.objects].sort((a, b) => a.objectNumber - b.objectNumber);
|
|
@@ -27914,6 +27921,7 @@ function serializeCosDocument(options) {
|
|
|
27914
27921
|
const packable = [];
|
|
27915
27922
|
const direct = [];
|
|
27916
27923
|
for (const obj of sorted) {
|
|
27924
|
+
if (++work % 16 === 0) yield;
|
|
27917
27925
|
const isLinearized = obj.value.kind === "dict" && dictGet(obj.value, "Linearized") !== void 0;
|
|
27918
27926
|
if (obj.value.kind !== "stream" && obj.generationNumber === 0 && !isLinearized) {
|
|
27919
27927
|
packable.push(obj);
|
|
@@ -27928,6 +27936,7 @@ function serializeCosDocument(options) {
|
|
|
27928
27936
|
const headerPairs = [];
|
|
27929
27937
|
let relOffset = 0;
|
|
27930
27938
|
for (const pObj of packable) {
|
|
27939
|
+
if (++work % 16 === 0) yield;
|
|
27931
27940
|
headerPairs.push(`${pObj.objectNumber} ${relOffset}`);
|
|
27932
27941
|
const bBytes = serializeCosNodeBytes(pObj.value);
|
|
27933
27942
|
const nl = textEncoder2.encode("\n");
|
|
@@ -27953,6 +27962,7 @@ function serializeCosDocument(options) {
|
|
|
27953
27962
|
];
|
|
27954
27963
|
const directOffsets = /* @__PURE__ */ new Map();
|
|
27955
27964
|
for (const dObj of allDirect) {
|
|
27965
|
+
if (++work % 16 === 0) yield;
|
|
27956
27966
|
directOffsets.set(dObj.objectNumber, { offset, generation: dObj.generationNumber });
|
|
27957
27967
|
const prefix = textEncoder2.encode(`${dObj.objectNumber} ${dObj.generationNumber} obj
|
|
27958
27968
|
`);
|
|
@@ -27963,6 +27973,7 @@ function serializeCosDocument(options) {
|
|
|
27963
27973
|
}
|
|
27964
27974
|
const compressedMap = /* @__PURE__ */ new Map();
|
|
27965
27975
|
for (let idx = 0; idx < packable.length; idx++) {
|
|
27976
|
+
if (++work % 16 === 0) yield;
|
|
27966
27977
|
compressedMap.set(packable[idx].objectNumber, idx);
|
|
27967
27978
|
}
|
|
27968
27979
|
const xrefOffset2 = offset;
|
|
@@ -27980,6 +27991,7 @@ function serializeCosDocument(options) {
|
|
|
27980
27991
|
};
|
|
27981
27992
|
writeEntry7(0, 0, 0, 65535);
|
|
27982
27993
|
for (let i = 1; i < size2; i++) {
|
|
27994
|
+
if (++work % 16 === 0) yield;
|
|
27983
27995
|
if (i === xrefStmNum) {
|
|
27984
27996
|
writeEntry7(i, 1, xrefOffset2, 0);
|
|
27985
27997
|
} else if (compressedMap.has(i)) {
|
|
@@ -28060,6 +28072,7 @@ ${xrefOffset2}
|
|
|
28060
28072
|
let pageCount = 0;
|
|
28061
28073
|
let firstPageObjNum = options.rootRef.objectNumber;
|
|
28062
28074
|
for (const o of sorted) {
|
|
28075
|
+
if (++work % 16 === 0) yield;
|
|
28063
28076
|
if (o.value.kind === "dict") {
|
|
28064
28077
|
const t = dictGet(o.value, "Type");
|
|
28065
28078
|
if (t?.kind === "name" && t.decoded === "Page") {
|
|
@@ -28107,6 +28120,7 @@ ${xrefOffset2}
|
|
|
28107
28120
|
}
|
|
28108
28121
|
const objectOffsets = /* @__PURE__ */ new Map();
|
|
28109
28122
|
for (const obj of sorted) {
|
|
28123
|
+
if (++work % 16 === 0) yield;
|
|
28110
28124
|
objectOffsets.set(obj.objectNumber, { offset, generation: obj.generationNumber });
|
|
28111
28125
|
let value = obj.value;
|
|
28112
28126
|
if (options.normalizeContent && value.kind === "stream" && value.decodedBytes) {
|
|
@@ -28138,6 +28152,7 @@ ${xrefOffset2}
|
|
|
28138
28152
|
0000000000 65535 f
|
|
28139
28153
|
`;
|
|
28140
28154
|
for (let i = 1; i < size; i++) {
|
|
28155
|
+
if (++work % 16 === 0) yield;
|
|
28141
28156
|
const entry = objectOffsets.get(i);
|
|
28142
28157
|
if (entry) {
|
|
28143
28158
|
xrefText += `${String(entry.offset).padStart(10, "0")} ${String(entry.generation).padStart(5, "0")} n
|
|
@@ -28184,6 +28199,7 @@ ${xrefOffset}
|
|
|
28184
28199
|
let endFirstPage = xrefOffset;
|
|
28185
28200
|
const sortedOffsets = [...objectOffsets.entries()].sort((a, b) => a[1].offset - b[1].offset);
|
|
28186
28201
|
for (let i = 0; i < sortedOffsets.length; i++) {
|
|
28202
|
+
if (++work % 16 === 0) yield;
|
|
28187
28203
|
const [objNum, info3] = sortedOffsets[i];
|
|
28188
28204
|
const nextOff = sortedOffsets[i + 1]?.[1].offset ?? xrefOffset;
|
|
28189
28205
|
if (objNum === hintObjAfter.objectNumber) {
|
|
@@ -28217,6 +28233,9 @@ ${xrefOffset}
|
|
|
28217
28233
|
}
|
|
28218
28234
|
return fullBytes;
|
|
28219
28235
|
}
|
|
28236
|
+
function serializeCosDocument(options) {
|
|
28237
|
+
return drainWork(serializeCosDocumentSteps(options));
|
|
28238
|
+
}
|
|
28220
28239
|
function appendIncrementalRevision(originalBytes, doc, updatedObjects) {
|
|
28221
28240
|
const chunks = [originalBytes, textEncoder2.encode("\n")];
|
|
28222
28241
|
let offset = originalBytes.length + 1;
|
|
@@ -28490,48 +28509,30 @@ function encryptPdfBuffer(state, objectNumber, generationNumber, plaintext) {
|
|
|
28490
28509
|
const objKey = md5Bytes([state.fileKey, suffix]).subarray(0, Math.min(16, state.fileKey.length + 5));
|
|
28491
28510
|
return rc4Transform(objKey, plaintext);
|
|
28492
28511
|
}
|
|
28493
|
-
function
|
|
28512
|
+
function* transformNodeStringsAndStreamsSteps(node, transform, transformStream) {
|
|
28513
|
+
yield;
|
|
28494
28514
|
switch (node.kind) {
|
|
28495
28515
|
case "string":
|
|
28496
|
-
return {
|
|
28497
|
-
|
|
28498
|
-
|
|
28499
|
-
|
|
28500
|
-
};
|
|
28501
|
-
|
|
28502
|
-
return {
|
|
28503
|
-
kind: "array",
|
|
28504
|
-
items: node.items.map((item) => transformNodeStringsAndStreams(item, transform, transformStream))
|
|
28505
|
-
};
|
|
28516
|
+
return { kind: "string", format: "hex", bytes: transform(node.bytes) };
|
|
28517
|
+
case "array": {
|
|
28518
|
+
const items = [];
|
|
28519
|
+
for (const item of node.items) items.push(yield* transformNodeStringsAndStreamsSteps(item, transform, transformStream));
|
|
28520
|
+
return { kind: "array", items };
|
|
28521
|
+
}
|
|
28506
28522
|
case "dict": {
|
|
28507
|
-
const type = dictGet(node, "Type");
|
|
28508
|
-
const fieldType = dictGet(node, "FT");
|
|
28509
|
-
const byteRange = dictGet(node, "ByteRange");
|
|
28523
|
+
const type = dictGet(node, "Type"), fieldType = dictGet(node, "FT"), byteRange = dictGet(node, "ByteRange");
|
|
28510
28524
|
const signature = type?.kind === "name" && type.decoded === "Sig" || fieldType?.kind === "name" && fieldType.decoded === "Sig" || byteRange?.kind === "array" && dictGet(node, "Filter")?.kind === "name";
|
|
28511
|
-
|
|
28512
|
-
|
|
28513
|
-
|
|
28514
|
-
key: e.key,
|
|
28515
|
-
value: signature && e.key.decoded === "Contents" ? e.value : transformNodeStringsAndStreams(e.value, transform, transformStream)
|
|
28516
|
-
}))
|
|
28517
|
-
};
|
|
28525
|
+
const entries = [];
|
|
28526
|
+
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) });
|
|
28527
|
+
return { kind: "dict", entries };
|
|
28518
28528
|
}
|
|
28519
28529
|
case "stream": {
|
|
28520
28530
|
const type = dictGet(node.dict, "Type");
|
|
28521
28531
|
if (type?.kind === "name" && type.decoded === "XRef") return node;
|
|
28522
28532
|
const stream = transformStream ? transformStream(node) : { ...node, rawBytes: transform(node.rawBytes) };
|
|
28523
|
-
const
|
|
28524
|
-
|
|
28525
|
-
|
|
28526
|
-
key: e.key,
|
|
28527
|
-
value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : transformNodeStringsAndStreams(e.value, transform, transformStream)
|
|
28528
|
-
}))
|
|
28529
|
-
};
|
|
28530
|
-
return {
|
|
28531
|
-
kind: "stream",
|
|
28532
|
-
dict: updatedDict,
|
|
28533
|
-
rawBytes: stream.rawBytes
|
|
28534
|
-
};
|
|
28533
|
+
const entries = [];
|
|
28534
|
+
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) });
|
|
28535
|
+
return { kind: "stream", dict: { kind: "dict", entries }, rawBytes: stream.rawBytes };
|
|
28535
28536
|
}
|
|
28536
28537
|
default:
|
|
28537
28538
|
return node;
|
|
@@ -28600,7 +28601,8 @@ function createR6Encryption(userPassword, ownerPassword, pMask) {
|
|
|
28600
28601
|
StrF: cosName("StdCF")
|
|
28601
28602
|
}) };
|
|
28602
28603
|
}
|
|
28603
|
-
function
|
|
28604
|
+
function* encryptCosDocumentSteps(doc, options = {}) {
|
|
28605
|
+
yield;
|
|
28604
28606
|
const userPassword = options.userPassword ?? "";
|
|
28605
28607
|
const ownerPassword = options.ownerPassword ?? userPassword;
|
|
28606
28608
|
const revision = options.revision ?? 6;
|
|
@@ -28622,14 +28624,15 @@ function encryptCosDocument(doc, options = {}) {
|
|
|
28622
28624
|
const encryptObjNum = maxObjNum + 1;
|
|
28623
28625
|
const encryptedObjects = [];
|
|
28624
28626
|
for (const obj of doc.objects.values()) {
|
|
28625
|
-
|
|
28627
|
+
yield;
|
|
28628
|
+
const transformed = yield* transformNodeStringsAndStreamsSteps(
|
|
28626
28629
|
obj.value,
|
|
28627
28630
|
(plain) => encryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, plain)
|
|
28628
28631
|
);
|
|
28629
28632
|
encryptedObjects.push({ objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: transformed });
|
|
28630
28633
|
}
|
|
28631
28634
|
encryptedObjects.push({ objectNumber: encryptObjNum, generationNumber: 0, value: encryptDict });
|
|
28632
|
-
return
|
|
28635
|
+
return yield* serializeCosDocumentSteps({
|
|
28633
28636
|
objects: encryptedObjects,
|
|
28634
28637
|
rootRef: doc.rootRef,
|
|
28635
28638
|
infoRef: doc.infoRef,
|
|
@@ -28679,17 +28682,19 @@ function decryptStream(doc, stream, transform) {
|
|
|
28679
28682
|
}
|
|
28680
28683
|
return { kind: "stream", dict, rawBytes: bytes };
|
|
28681
28684
|
}
|
|
28682
|
-
function
|
|
28685
|
+
function* decryptCosDocumentSteps(doc, state) {
|
|
28686
|
+
yield;
|
|
28683
28687
|
const encryptObjNum = doc.encryptRef?.objectNumber;
|
|
28684
28688
|
const handler = securityHandlers.get(state);
|
|
28685
28689
|
for (const [num, obj] of doc.objects.entries()) {
|
|
28690
|
+
yield;
|
|
28686
28691
|
if (num === encryptObjNum || handler?.plaintextObjects.has(num)) continue;
|
|
28687
28692
|
if (obj.value.kind === "stream") {
|
|
28688
28693
|
const type = doc.resolve(dictGet(obj.value.dict, "Type"));
|
|
28689
28694
|
if (type?.kind === "name" && (type.decoded === "XRef" || type.decoded === "Metadata" && !state.encryptMetadata)) continue;
|
|
28690
28695
|
}
|
|
28691
28696
|
const transform = handler?.factory.createCipherTransform(obj.objectNumber, obj.generationNumber);
|
|
28692
|
-
const decrypted =
|
|
28697
|
+
const decrypted = yield* transformNodeStringsAndStreamsSteps(
|
|
28693
28698
|
obj.value,
|
|
28694
28699
|
(cipher) => decryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, cipher),
|
|
28695
28700
|
transform ? (stream) => decryptStream(doc, stream, transform) : void 0
|
|
@@ -28803,9 +28808,12 @@ var ParsedCosDocument = class {
|
|
|
28803
28808
|
return void 0;
|
|
28804
28809
|
}
|
|
28805
28810
|
};
|
|
28806
|
-
function
|
|
28811
|
+
function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
|
|
28812
|
+
yield;
|
|
28813
|
+
let work = 0;
|
|
28807
28814
|
const stack = [];
|
|
28808
28815
|
while (true) {
|
|
28816
|
+
if (++work % 16 === 0) yield;
|
|
28809
28817
|
const tok = lexer.nextToken();
|
|
28810
28818
|
const parent = stack.at(-1);
|
|
28811
28819
|
if (!tok) {
|
|
@@ -29001,7 +29009,8 @@ function parseHeaderVersion(bytes) {
|
|
|
29001
29009
|
}
|
|
29002
29010
|
return head.slice(idx + 5, idx + 8);
|
|
29003
29011
|
}
|
|
29004
|
-
function
|
|
29012
|
+
function* parseObjectAtOffsetSteps(bytes, offset, maxRecursionDepth, repair = false) {
|
|
29013
|
+
yield;
|
|
29005
29014
|
const lexer = new CosByteLexer(bytes, offset);
|
|
29006
29015
|
const objNumTok = lexer.nextToken();
|
|
29007
29016
|
const genNumTok = lexer.nextToken();
|
|
@@ -29009,7 +29018,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
|
|
|
29009
29018
|
if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
|
|
29010
29019
|
throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
|
|
29011
29020
|
}
|
|
29012
|
-
const value =
|
|
29021
|
+
const value = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, repair);
|
|
29013
29022
|
if (!value) {
|
|
29014
29023
|
throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
|
|
29015
29024
|
}
|
|
@@ -29020,7 +29029,9 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
|
|
|
29020
29029
|
span: { start: objNumTok.span.start, end: lexer.offset }
|
|
29021
29030
|
};
|
|
29022
29031
|
}
|
|
29023
|
-
function
|
|
29032
|
+
function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
|
|
29033
|
+
yield;
|
|
29034
|
+
let work = 0;
|
|
29024
29035
|
if (xrefOffset < 0 || xrefOffset >= bytes.length) {
|
|
29025
29036
|
throw new PdfError("E_PARSE", `Invalid xref offset: ${xrefOffset}`);
|
|
29026
29037
|
}
|
|
@@ -29032,6 +29043,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
29032
29043
|
if (firstTok.kind === "keyword" && firstTok.value === "xref") {
|
|
29033
29044
|
const entries2 = /* @__PURE__ */ new Map();
|
|
29034
29045
|
while (true) {
|
|
29046
|
+
if (++work % 16 === 0) yield;
|
|
29035
29047
|
const saved = lexer.offset;
|
|
29036
29048
|
const tok = lexer.nextToken();
|
|
29037
29049
|
if (!tok) {
|
|
@@ -29055,6 +29067,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
29055
29067
|
}
|
|
29056
29068
|
if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
29057
29069
|
for (let i = 0; i < count; i++) {
|
|
29070
|
+
if (++work % 16 === 0) yield;
|
|
29058
29071
|
const offTok = lexer.nextToken();
|
|
29059
29072
|
const genTok = lexer.nextToken();
|
|
29060
29073
|
const flagTok = lexer.nextToken();
|
|
@@ -29080,7 +29093,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
29080
29093
|
if (entries2.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
29081
29094
|
}
|
|
29082
29095
|
}
|
|
29083
|
-
const trailerNode =
|
|
29096
|
+
const trailerNode = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth);
|
|
29084
29097
|
if (!trailerNode || trailerNode.kind !== "dict") {
|
|
29085
29098
|
throw new PdfError("E_PARSE", "Missing trailer dictionary after xref table");
|
|
29086
29099
|
}
|
|
@@ -29092,7 +29105,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
29092
29105
|
previousXrefOffset: prevNode2?.kind === "number" ? prevNode2.value : void 0
|
|
29093
29106
|
};
|
|
29094
29107
|
}
|
|
29095
|
-
const xrefObj =
|
|
29108
|
+
const xrefObj = yield* parseObjectAtOffsetSteps(bytes, xrefOffset, maxRecursionDepth);
|
|
29096
29109
|
if (xrefObj.value.kind !== "stream") {
|
|
29097
29110
|
throw new PdfError("E_PARSE", `Expected xref table or XRef stream at offset ${xrefOffset}`);
|
|
29098
29111
|
}
|
|
@@ -29113,6 +29126,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
29113
29126
|
if (indexArray) {
|
|
29114
29127
|
if (indexArray.kind !== "array" || indexArray.items.length % 2 !== 0) throw new PdfError("E_PARSE", "Invalid XRef range fields");
|
|
29115
29128
|
for (let i = 0; i < indexArray.items.length; i += 2) {
|
|
29129
|
+
if (++work % 16 === 0) yield;
|
|
29116
29130
|
const first = indexArray.items[i];
|
|
29117
29131
|
const count = indexArray.items[i + 1];
|
|
29118
29132
|
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)) {
|
|
@@ -29135,9 +29149,11 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
29135
29149
|
return v;
|
|
29136
29150
|
};
|
|
29137
29151
|
for (const [startObj, count] of subsections) {
|
|
29152
|
+
if (++work % 16 === 0) yield;
|
|
29138
29153
|
if (count > (decoded.length - pos) / stride) throw new PdfError("E_PARSE", "Truncated XRef stream");
|
|
29139
29154
|
if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
29140
29155
|
for (let i = 0; i < count; i++) {
|
|
29156
|
+
if (++work % 16 === 0) yield;
|
|
29141
29157
|
const objNum = startObj + i;
|
|
29142
29158
|
const field0 = w0 > 0 ? readInt(w0) : 1;
|
|
29143
29159
|
const field1 = readInt(w1);
|
|
@@ -29183,12 +29199,16 @@ function isAsciiWhitespace(ch3) {
|
|
|
29183
29199
|
function isAsciiDigit(ch3) {
|
|
29184
29200
|
return ch3 >= 48 && ch3 <= 57;
|
|
29185
29201
|
}
|
|
29186
|
-
function
|
|
29202
|
+
function* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth) {
|
|
29203
|
+
yield;
|
|
29204
|
+
let work = 0;
|
|
29187
29205
|
const objects = /* @__PURE__ */ new Map();
|
|
29188
29206
|
const trailers = [];
|
|
29189
29207
|
let pos = 0;
|
|
29190
29208
|
while (pos < bytes.length) {
|
|
29209
|
+
if (++work % 16 === 0) yield;
|
|
29191
29210
|
while (pos < bytes.length && !isAsciiDigit(bytes[pos])) {
|
|
29211
|
+
if (++work % 16 === 0) yield;
|
|
29192
29212
|
if (bytes[pos] === 37) {
|
|
29193
29213
|
while (pos < bytes.length && bytes[pos] !== 10 && bytes[pos] !== 13) pos++;
|
|
29194
29214
|
continue;
|
|
@@ -29198,7 +29218,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
29198
29218
|
try {
|
|
29199
29219
|
const token = lexer.nextToken();
|
|
29200
29220
|
if (token?.kind === "keyword" && token.value === "trailer") {
|
|
29201
|
-
const trailer =
|
|
29221
|
+
const trailer = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, true);
|
|
29202
29222
|
if (trailer?.kind === "dict") trailers.push(trailer);
|
|
29203
29223
|
pos = lexer.offset;
|
|
29204
29224
|
continue;
|
|
@@ -29231,7 +29251,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
29231
29251
|
bytes[pos + 3] === 40)) {
|
|
29232
29252
|
pos += 3;
|
|
29233
29253
|
try {
|
|
29234
|
-
const parsed =
|
|
29254
|
+
const parsed = yield* parseObjectAtOffsetSteps(bytes, headerStart, maxRecursionDepth, true);
|
|
29235
29255
|
objects.set(parsed.objectNumber, parsed);
|
|
29236
29256
|
if (parsed.value.kind === "stream") {
|
|
29237
29257
|
const type = dictGet(parsed.value.dict, "Type");
|
|
@@ -29248,13 +29268,17 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
29248
29268
|
}
|
|
29249
29269
|
return { objects, trailers };
|
|
29250
29270
|
}
|
|
29251
|
-
function
|
|
29271
|
+
function* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
|
|
29272
|
+
yield;
|
|
29273
|
+
let work = 0;
|
|
29252
29274
|
for (const obj of [...objects.values()]) {
|
|
29275
|
+
if (++work % 16 === 0) yield;
|
|
29253
29276
|
if (obj.value.kind === "stream") {
|
|
29254
29277
|
const t = dictGet(obj.value.dict, "Type");
|
|
29255
29278
|
if (t?.kind === "name" && t.decoded === "ObjStm") {
|
|
29256
29279
|
try {
|
|
29257
|
-
for (const [unpackedNum, unpackedVal] of
|
|
29280
|
+
for (const [unpackedNum, unpackedVal] of (yield* unpackObjectStreamSteps(obj.value, maxDecompressedBytes, maxRecursionDepth, true)).entries()) {
|
|
29281
|
+
if (++work % 16 === 0) yield;
|
|
29258
29282
|
if (!objects.has(unpackedNum)) {
|
|
29259
29283
|
objects.set(unpackedNum, {
|
|
29260
29284
|
objectNumber: unpackedNum,
|
|
@@ -29290,7 +29314,9 @@ function recoveredReferences(objects) {
|
|
|
29290
29314
|
}
|
|
29291
29315
|
return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
|
|
29292
29316
|
}
|
|
29293
|
-
function
|
|
29317
|
+
function* unpackObjectStreamSteps(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
|
|
29318
|
+
yield;
|
|
29319
|
+
let work = 0;
|
|
29294
29320
|
const nNode = dictGet(streamObj.dict, "N");
|
|
29295
29321
|
const firstNode = dictGet(streamObj.dict, "First");
|
|
29296
29322
|
if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
|
|
@@ -29300,6 +29326,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
29300
29326
|
const headerLexer = new CosByteLexer(decoded, 0);
|
|
29301
29327
|
const pairs = [];
|
|
29302
29328
|
for (let i = 0; i < nNode.value; i++) {
|
|
29329
|
+
if (++work % 16 === 0) yield;
|
|
29303
29330
|
const numTok = headerLexer.nextToken();
|
|
29304
29331
|
const offTok = headerLexer.nextToken();
|
|
29305
29332
|
if (numTok?.kind === "number" && offTok?.kind === "number") {
|
|
@@ -29308,9 +29335,10 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
29308
29335
|
}
|
|
29309
29336
|
const result = /* @__PURE__ */ new Map();
|
|
29310
29337
|
for (const pair of pairs) {
|
|
29338
|
+
if (++work % 16 === 0) yield;
|
|
29311
29339
|
try {
|
|
29312
29340
|
const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
|
|
29313
|
-
const node =
|
|
29341
|
+
const node = yield* parseNodeFromLexerSteps(valLexer, decoded, maxRecursionDepth, repair);
|
|
29314
29342
|
if (node) {
|
|
29315
29343
|
result.set(pair.objectNumber, node);
|
|
29316
29344
|
}
|
|
@@ -29320,7 +29348,9 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
29320
29348
|
}
|
|
29321
29349
|
return result;
|
|
29322
29350
|
}
|
|
29323
|
-
function
|
|
29351
|
+
function* parseCosDocumentSteps(bytes, options = {}) {
|
|
29352
|
+
yield;
|
|
29353
|
+
let work = 0;
|
|
29324
29354
|
const version = parseHeaderVersion(bytes);
|
|
29325
29355
|
const recovery = options.recovery ?? "strict";
|
|
29326
29356
|
const maxObjects = options.maxObjects ?? Infinity;
|
|
@@ -29355,10 +29385,12 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29355
29385
|
let currentXrefOffset = offsetTok.value;
|
|
29356
29386
|
const visitedOffsets = /* @__PURE__ */ new Set();
|
|
29357
29387
|
while (currentXrefOffset !== void 0 && !visitedOffsets.has(currentXrefOffset)) {
|
|
29388
|
+
if (++work % 16 === 0) yield;
|
|
29358
29389
|
visitedOffsets.add(currentXrefOffset);
|
|
29359
|
-
const rev =
|
|
29390
|
+
const rev = yield* parseXrefRevisionAtSteps(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
|
|
29360
29391
|
revisions.push(rev);
|
|
29361
29392
|
for (const [num, entry] of rev.entries.entries()) {
|
|
29393
|
+
if (++work % 16 === 0) yield;
|
|
29362
29394
|
if (!mergedXref.has(num)) {
|
|
29363
29395
|
mergedXref.set(num, entry);
|
|
29364
29396
|
if (mergedXref.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
@@ -29391,8 +29423,9 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29391
29423
|
if (!useRepair && rootRef) {
|
|
29392
29424
|
try {
|
|
29393
29425
|
for (const [objNum, entry] of mergedXref.entries()) {
|
|
29426
|
+
if (++work % 16 === 0) yield;
|
|
29394
29427
|
if (entry.type !== "uncompressed") continue;
|
|
29395
|
-
const parsed =
|
|
29428
|
+
const parsed = yield* parseObjectAtOffsetSteps(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
|
|
29396
29429
|
if (parsed.objectNumber !== objNum || parsed.generationNumber !== (entry.generationNumber ?? 0)) {
|
|
29397
29430
|
throw new PdfError("E_PARSE", `Bad uncompressed XRef entry for object ${objNum}`);
|
|
29398
29431
|
}
|
|
@@ -29410,7 +29443,7 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29410
29443
|
throw new PdfError("E_PARSE", "PDF trailer missing /Root reference");
|
|
29411
29444
|
}
|
|
29412
29445
|
useRepair = true;
|
|
29413
|
-
const scanned =
|
|
29446
|
+
const scanned = yield* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth);
|
|
29414
29447
|
objects = scanned.objects;
|
|
29415
29448
|
revisions.length = 0;
|
|
29416
29449
|
mergedXref.clear();
|
|
@@ -29445,7 +29478,7 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29445
29478
|
encryptNode = encrypt?.kind === "ref" || encrypt?.kind === "dict" ? encrypt : void 0;
|
|
29446
29479
|
encryptRef = encrypt?.kind === "ref" ? encrypt : void 0;
|
|
29447
29480
|
idArray = id?.kind === "array" ? id : void 0;
|
|
29448
|
-
if (!rootRef && !encryptNode)
|
|
29481
|
+
if (!rootRef && !encryptNode) yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
|
|
29449
29482
|
const fallback = recoveredReferences(objects);
|
|
29450
29483
|
rootRef ??= fallback.rootRef;
|
|
29451
29484
|
infoRef ??= fallback.infoRef;
|
|
@@ -29480,20 +29513,21 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29480
29513
|
maxRecursionDepth
|
|
29481
29514
|
});
|
|
29482
29515
|
doc.encryption = encState;
|
|
29483
|
-
|
|
29516
|
+
yield* decryptCosDocumentSteps(doc, encState);
|
|
29484
29517
|
}
|
|
29485
29518
|
if (useRepair) {
|
|
29486
|
-
|
|
29519
|
+
yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
|
|
29487
29520
|
doc.infoRef ??= recoveredReferences(objects).infoRef;
|
|
29488
29521
|
}
|
|
29489
29522
|
const objStmCache = /* @__PURE__ */ new Map();
|
|
29490
29523
|
for (const [objNum, entry] of mergedXref.entries()) {
|
|
29524
|
+
if (++work % 16 === 0) yield;
|
|
29491
29525
|
if (entry.type === "compressed" && entry.objectStreamNumber !== void 0) {
|
|
29492
29526
|
let unpacked = objStmCache.get(entry.objectStreamNumber);
|
|
29493
29527
|
if (!unpacked) {
|
|
29494
29528
|
const stmObj = objects.get(entry.objectStreamNumber)?.value;
|
|
29495
29529
|
if (stmObj?.kind === "stream") {
|
|
29496
|
-
unpacked =
|
|
29530
|
+
unpacked = yield* unpackObjectStreamSteps(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
|
|
29497
29531
|
objStmCache.set(entry.objectStreamNumber, unpacked);
|
|
29498
29532
|
}
|
|
29499
29533
|
}
|
|
@@ -29510,6 +29544,9 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29510
29544
|
}
|
|
29511
29545
|
return doc;
|
|
29512
29546
|
}
|
|
29547
|
+
function parseCosDocument(bytes, options = {}) {
|
|
29548
|
+
return drainWork(parseCosDocumentSteps(bytes, options));
|
|
29549
|
+
}
|
|
29513
29550
|
var WIN_ANSI_HIGH_BYTES = {
|
|
29514
29551
|
128: 8364,
|
|
29515
29552
|
130: 8218,
|
|
@@ -40885,7 +40922,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
|
|
|
40885
40922
|
}
|
|
40886
40923
|
return void 0;
|
|
40887
40924
|
}
|
|
40888
|
-
function
|
|
40925
|
+
function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
|
|
40926
|
+
if (++yieldState.work % 256 === 0) yield;
|
|
40889
40927
|
const dict = doc.resolveDict(node);
|
|
40890
40928
|
if (!dict) return out;
|
|
40891
40929
|
const tNode = doc.resolve(dictGet(dict, "T"));
|
|
@@ -40918,7 +40956,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
|
|
|
40918
40956
|
return out;
|
|
40919
40957
|
}
|
|
40920
40958
|
for (const kid of kidsArr.items) {
|
|
40921
|
-
|
|
40959
|
+
if (++yieldState.work % 16 === 0) yield;
|
|
40960
|
+
yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
|
|
40922
40961
|
}
|
|
40923
40962
|
} else if (fullName) {
|
|
40924
40963
|
out.push({
|
|
@@ -41359,6 +41398,9 @@ function escapePdfLiteralString(str) {
|
|
|
41359
41398
|
}
|
|
41360
41399
|
return out;
|
|
41361
41400
|
}
|
|
41401
|
+
function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
|
|
41402
|
+
drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
|
|
41403
|
+
}
|
|
41362
41404
|
var PdfPage = class {
|
|
41363
41405
|
cosDoc;
|
|
41364
41406
|
pageRef;
|
|
@@ -44436,14 +44478,18 @@ var PdfDocument = class _PdfDocument {
|
|
|
44436
44478
|
});
|
|
44437
44479
|
return new _PdfDocument(parseCosDocument(rawBytes));
|
|
44438
44480
|
}
|
|
44439
|
-
static
|
|
44481
|
+
static *loadSteps(bytes, options) {
|
|
44482
|
+
yield;
|
|
44440
44483
|
return new _PdfDocument(
|
|
44441
|
-
|
|
44484
|
+
yield* parseCosDocumentSteps(bytes, {
|
|
44442
44485
|
...options,
|
|
44443
44486
|
recovery: options?.recovery ?? "repair"
|
|
44444
44487
|
})
|
|
44445
44488
|
);
|
|
44446
44489
|
}
|
|
44490
|
+
static load(bytes, options) {
|
|
44491
|
+
return drainWork(_PdfDocument.loadSteps(bytes, options));
|
|
44492
|
+
}
|
|
44447
44493
|
rebuildPagesList() {
|
|
44448
44494
|
const catalog = this.cos.resolveDict(this.cos.rootRef);
|
|
44449
44495
|
const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
|
|
@@ -44525,20 +44571,30 @@ var PdfDocument = class _PdfDocument {
|
|
|
44525
44571
|
this.pages.splice(index, 1);
|
|
44526
44572
|
this.syncPageTree();
|
|
44527
44573
|
}
|
|
44528
|
-
|
|
44574
|
+
*copyPagesFromSteps(sourceDoc, indices) {
|
|
44575
|
+
function* cloneItems(items) {
|
|
44576
|
+
const result = [];
|
|
44577
|
+
for (const item of items) result.push(yield* cloneNode(item));
|
|
44578
|
+
return result;
|
|
44579
|
+
}
|
|
44580
|
+
yield;
|
|
44581
|
+
let work = 0;
|
|
44529
44582
|
const memo = /* @__PURE__ */ new Map();
|
|
44530
44583
|
const sourcePageObjNums = /* @__PURE__ */ new Set();
|
|
44531
44584
|
for (let i = 0; i < sourceDoc.getPageCount(); i++) {
|
|
44585
|
+
if (++work % 16 === 0) yield;
|
|
44532
44586
|
sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
|
|
44533
44587
|
}
|
|
44534
44588
|
const targetPageRefs = [];
|
|
44535
44589
|
for (const idx of indices) {
|
|
44590
|
+
if (++work % 16 === 0) yield;
|
|
44536
44591
|
const srcPage = sourceDoc.getPage(idx);
|
|
44537
44592
|
const pageRef = this.cos.allocateObject({ kind: "null" });
|
|
44538
44593
|
targetPageRefs.push(pageRef);
|
|
44539
44594
|
memo.set(srcPage.ref.objectNumber, pageRef);
|
|
44540
44595
|
}
|
|
44541
|
-
const cloneNode = (node)
|
|
44596
|
+
const cloneNode = function* (node) {
|
|
44597
|
+
if (++work % 16 === 0) yield;
|
|
44542
44598
|
if (node.kind === "ref") {
|
|
44543
44599
|
const existing = memo.get(node.objectNumber);
|
|
44544
44600
|
if (existing) return existing;
|
|
@@ -44549,12 +44605,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
44549
44605
|
if (!target) return cosRef(0);
|
|
44550
44606
|
const placeholderRef = this.cos.allocateObject({ kind: "null" });
|
|
44551
44607
|
memo.set(node.objectNumber, placeholderRef);
|
|
44552
|
-
const clonedTarget = cloneNode(target);
|
|
44608
|
+
const clonedTarget = yield* cloneNode(target);
|
|
44553
44609
|
this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
|
|
44554
44610
|
return placeholderRef;
|
|
44555
44611
|
}
|
|
44556
44612
|
if (node.kind === "array") {
|
|
44557
|
-
return cosArray(node.items
|
|
44613
|
+
return cosArray(yield* cloneItems(node.items));
|
|
44558
44614
|
}
|
|
44559
44615
|
if (node.kind === "dict") {
|
|
44560
44616
|
const typeEntry = dictGet(node, "Type");
|
|
@@ -44564,13 +44620,13 @@ var PdfDocument = class _PdfDocument {
|
|
|
44564
44620
|
if (isPageTreeNode && entry.key.decoded === "Parent") continue;
|
|
44565
44621
|
newEntries.push({
|
|
44566
44622
|
key: { ...entry.key },
|
|
44567
|
-
value: cloneNode(entry.value)
|
|
44623
|
+
value: yield* cloneNode(entry.value)
|
|
44568
44624
|
});
|
|
44569
44625
|
}
|
|
44570
44626
|
return { kind: "dict", entries: newEntries };
|
|
44571
44627
|
}
|
|
44572
44628
|
if (node.kind === "stream") {
|
|
44573
|
-
const clonedDict = cloneNode(node.dict);
|
|
44629
|
+
const clonedDict = yield* cloneNode(node.dict);
|
|
44574
44630
|
return {
|
|
44575
44631
|
kind: "stream",
|
|
44576
44632
|
dict: clonedDict,
|
|
@@ -44579,11 +44635,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
44579
44635
|
};
|
|
44580
44636
|
}
|
|
44581
44637
|
return node;
|
|
44582
|
-
};
|
|
44638
|
+
}.bind(this);
|
|
44583
44639
|
const copiedPages = [];
|
|
44584
44640
|
for (const [position, idx] of indices.entries()) {
|
|
44641
|
+
if (++work % 16 === 0) yield;
|
|
44585
44642
|
const srcPage = sourceDoc.getPage(idx);
|
|
44586
|
-
const clonedPageDict = cloneNode(srcPage.pageDict);
|
|
44643
|
+
const clonedPageDict = yield* cloneNode(srcPage.pageDict);
|
|
44587
44644
|
const size = srcPage.getSize();
|
|
44588
44645
|
if (!dictGet(clonedPageDict, "MediaBox")) {
|
|
44589
44646
|
dictSet(
|
|
@@ -44593,13 +44650,14 @@ var PdfDocument = class _PdfDocument {
|
|
|
44593
44650
|
);
|
|
44594
44651
|
}
|
|
44595
44652
|
if (!dictGet(clonedPageDict, "Resources")) {
|
|
44596
|
-
dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
|
|
44653
|
+
dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
|
|
44597
44654
|
}
|
|
44598
44655
|
if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
|
|
44599
44656
|
dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
|
|
44600
44657
|
}
|
|
44601
44658
|
const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
|
|
44602
44659
|
for (const boxKey of inheritedBoxKeys) {
|
|
44660
|
+
if (++work % 16 === 0) yield;
|
|
44603
44661
|
if (!dictGet(clonedPageDict, boxKey)) {
|
|
44604
44662
|
const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
|
|
44605
44663
|
if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
|
|
@@ -44641,8 +44699,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
44641
44699
|
};
|
|
44642
44700
|
const clonedRootFieldRefs = [];
|
|
44643
44701
|
for (const item of srcFieldsArr.items) {
|
|
44702
|
+
if (++work % 16 === 0) yield;
|
|
44644
44703
|
if (!hasClonedDescendant(item)) continue;
|
|
44645
|
-
const cloned = cloneNode(item);
|
|
44704
|
+
const cloned = yield* cloneNode(item);
|
|
44646
44705
|
if (cloned.kind === "ref") {
|
|
44647
44706
|
const clonedDict = this.cos.resolveDict(cloned);
|
|
44648
44707
|
const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
|
|
@@ -44676,6 +44735,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
44676
44735
|
dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
|
|
44677
44736
|
);
|
|
44678
44737
|
for (const fRef of clonedRootFieldRefs) {
|
|
44738
|
+
if (++work % 16 === 0) yield;
|
|
44679
44739
|
if (!existingNums.has(fRef.objectNumber)) {
|
|
44680
44740
|
dstFields.items.push(fRef);
|
|
44681
44741
|
existingNums.add(fRef.objectNumber);
|
|
@@ -44683,11 +44743,11 @@ var PdfDocument = class _PdfDocument {
|
|
|
44683
44743
|
}
|
|
44684
44744
|
const srcDr = dictGet(srcAcroForm, "DR");
|
|
44685
44745
|
if (srcDr && !dictGet(dstAcroForm, "DR")) {
|
|
44686
|
-
dictSet(dstAcroForm, "DR", cloneNode(srcDr));
|
|
44746
|
+
dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
|
|
44687
44747
|
}
|
|
44688
44748
|
const srcDa = dictGet(srcAcroForm, "DA");
|
|
44689
44749
|
if (srcDa && !dictGet(dstAcroForm, "DA")) {
|
|
44690
|
-
dictSet(dstAcroForm, "DA", cloneNode(srcDa));
|
|
44750
|
+
dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
|
|
44691
44751
|
}
|
|
44692
44752
|
}
|
|
44693
44753
|
}
|
|
@@ -44696,12 +44756,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
44696
44756
|
if (srcOcProps) {
|
|
44697
44757
|
const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
|
|
44698
44758
|
if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
|
|
44699
|
-
dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
|
|
44759
|
+
dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
|
|
44700
44760
|
}
|
|
44701
44761
|
}
|
|
44702
44762
|
this.syncPageTree();
|
|
44703
44763
|
return copiedPages;
|
|
44704
44764
|
}
|
|
44765
|
+
copyPagesFrom(sourceDoc, indices) {
|
|
44766
|
+
return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
|
|
44767
|
+
}
|
|
44705
44768
|
embedStandardFont(fontName) {
|
|
44706
44769
|
return createStandardFontHandle(fontName);
|
|
44707
44770
|
}
|
|
@@ -44901,14 +44964,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
44901
44964
|
});
|
|
44902
44965
|
return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
|
|
44903
44966
|
}
|
|
44904
|
-
|
|
44967
|
+
*saveSteps(options = {}) {
|
|
44968
|
+
yield;
|
|
44905
44969
|
this.syncPageTree();
|
|
44906
44970
|
if (this.cos.requiresFullRewrite) {
|
|
44907
44971
|
pruneUnusedXObjects(this.cos, this.pages);
|
|
44908
44972
|
discardUnreachableObjects(this.cos);
|
|
44909
44973
|
}
|
|
44910
44974
|
if (options.encrypt) {
|
|
44911
|
-
return
|
|
44975
|
+
return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
|
|
44912
44976
|
}
|
|
44913
44977
|
const allObjects = [...this.cos.objects.values()].sort(
|
|
44914
44978
|
(a, b) => a.objectNumber - b.objectNumber
|
|
@@ -44916,7 +44980,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
44916
44980
|
if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
|
|
44917
44981
|
return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
|
|
44918
44982
|
}
|
|
44919
|
-
return
|
|
44983
|
+
return yield* serializeCosDocumentSteps({
|
|
44920
44984
|
objects: allObjects,
|
|
44921
44985
|
rootRef: this.cos.rootRef,
|
|
44922
44986
|
infoRef: this.cos.infoRef,
|
|
@@ -44927,6 +44991,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
44927
44991
|
linearize: options.linearize
|
|
44928
44992
|
});
|
|
44929
44993
|
}
|
|
44994
|
+
save(options = {}) {
|
|
44995
|
+
return drainWork(this.saveSteps(options));
|
|
44996
|
+
}
|
|
44930
44997
|
};
|
|
44931
44998
|
function resolveDestinationPageIndex(doc, destOrActionNode) {
|
|
44932
44999
|
const cos = doc.cos;
|