@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
|
@@ -27102,6 +27102,11 @@ function tokenizeCos(bytes, start = 0, end = bytes.length) {
|
|
|
27102
27102
|
}
|
|
27103
27103
|
return tokens;
|
|
27104
27104
|
}
|
|
27105
|
+
function drainWork(work) {
|
|
27106
|
+
let step = work.next();
|
|
27107
|
+
while (!step.done) step = work.next();
|
|
27108
|
+
return step.value;
|
|
27109
|
+
}
|
|
27105
27110
|
function bytesToString3(bytes) {
|
|
27106
27111
|
if (typeof bytes !== "object" || bytes?.length === void 0) {
|
|
27107
27112
|
throw new Error("Invalid argument for bytesToString");
|
|
@@ -27697,7 +27702,9 @@ function concatByteArrays(chunks) {
|
|
|
27697
27702
|
}
|
|
27698
27703
|
return out;
|
|
27699
27704
|
}
|
|
27700
|
-
function
|
|
27705
|
+
function* serializeCosDocumentSteps(options) {
|
|
27706
|
+
yield;
|
|
27707
|
+
let work = 0;
|
|
27701
27708
|
const maxOutputBytes = options.maxOutputBytes ?? Infinity;
|
|
27702
27709
|
const maxObjects = options.maxObjects ?? Infinity;
|
|
27703
27710
|
const sorted = [...options.objects].sort((a, b) => a.objectNumber - b.objectNumber);
|
|
@@ -27720,6 +27727,7 @@ function serializeCosDocument(options) {
|
|
|
27720
27727
|
const packable = [];
|
|
27721
27728
|
const direct = [];
|
|
27722
27729
|
for (const obj of sorted) {
|
|
27730
|
+
if (++work % 16 === 0) yield;
|
|
27723
27731
|
const isLinearized = obj.value.kind === "dict" && dictGet(obj.value, "Linearized") !== void 0;
|
|
27724
27732
|
if (obj.value.kind !== "stream" && obj.generationNumber === 0 && !isLinearized) {
|
|
27725
27733
|
packable.push(obj);
|
|
@@ -27734,6 +27742,7 @@ function serializeCosDocument(options) {
|
|
|
27734
27742
|
const headerPairs = [];
|
|
27735
27743
|
let relOffset = 0;
|
|
27736
27744
|
for (const pObj of packable) {
|
|
27745
|
+
if (++work % 16 === 0) yield;
|
|
27737
27746
|
headerPairs.push(`${pObj.objectNumber} ${relOffset}`);
|
|
27738
27747
|
const bBytes = serializeCosNodeBytes(pObj.value);
|
|
27739
27748
|
const nl = textEncoder2.encode("\n");
|
|
@@ -27759,6 +27768,7 @@ function serializeCosDocument(options) {
|
|
|
27759
27768
|
];
|
|
27760
27769
|
const directOffsets = /* @__PURE__ */ new Map();
|
|
27761
27770
|
for (const dObj of allDirect) {
|
|
27771
|
+
if (++work % 16 === 0) yield;
|
|
27762
27772
|
directOffsets.set(dObj.objectNumber, { offset, generation: dObj.generationNumber });
|
|
27763
27773
|
const prefix = textEncoder2.encode(`${dObj.objectNumber} ${dObj.generationNumber} obj
|
|
27764
27774
|
`);
|
|
@@ -27769,6 +27779,7 @@ function serializeCosDocument(options) {
|
|
|
27769
27779
|
}
|
|
27770
27780
|
const compressedMap = /* @__PURE__ */ new Map();
|
|
27771
27781
|
for (let idx = 0; idx < packable.length; idx++) {
|
|
27782
|
+
if (++work % 16 === 0) yield;
|
|
27772
27783
|
compressedMap.set(packable[idx].objectNumber, idx);
|
|
27773
27784
|
}
|
|
27774
27785
|
const xrefOffset2 = offset;
|
|
@@ -27786,6 +27797,7 @@ function serializeCosDocument(options) {
|
|
|
27786
27797
|
};
|
|
27787
27798
|
writeEntry7(0, 0, 0, 65535);
|
|
27788
27799
|
for (let i = 1; i < size2; i++) {
|
|
27800
|
+
if (++work % 16 === 0) yield;
|
|
27789
27801
|
if (i === xrefStmNum) {
|
|
27790
27802
|
writeEntry7(i, 1, xrefOffset2, 0);
|
|
27791
27803
|
} else if (compressedMap.has(i)) {
|
|
@@ -27866,6 +27878,7 @@ ${xrefOffset2}
|
|
|
27866
27878
|
let pageCount = 0;
|
|
27867
27879
|
let firstPageObjNum = options.rootRef.objectNumber;
|
|
27868
27880
|
for (const o of sorted) {
|
|
27881
|
+
if (++work % 16 === 0) yield;
|
|
27869
27882
|
if (o.value.kind === "dict") {
|
|
27870
27883
|
const t = dictGet(o.value, "Type");
|
|
27871
27884
|
if (t?.kind === "name" && t.decoded === "Page") {
|
|
@@ -27913,6 +27926,7 @@ ${xrefOffset2}
|
|
|
27913
27926
|
}
|
|
27914
27927
|
const objectOffsets = /* @__PURE__ */ new Map();
|
|
27915
27928
|
for (const obj of sorted) {
|
|
27929
|
+
if (++work % 16 === 0) yield;
|
|
27916
27930
|
objectOffsets.set(obj.objectNumber, { offset, generation: obj.generationNumber });
|
|
27917
27931
|
let value = obj.value;
|
|
27918
27932
|
if (options.normalizeContent && value.kind === "stream" && value.decodedBytes) {
|
|
@@ -27944,6 +27958,7 @@ ${xrefOffset2}
|
|
|
27944
27958
|
0000000000 65535 f
|
|
27945
27959
|
`;
|
|
27946
27960
|
for (let i = 1; i < size; i++) {
|
|
27961
|
+
if (++work % 16 === 0) yield;
|
|
27947
27962
|
const entry = objectOffsets.get(i);
|
|
27948
27963
|
if (entry) {
|
|
27949
27964
|
xrefText += `${String(entry.offset).padStart(10, "0")} ${String(entry.generation).padStart(5, "0")} n
|
|
@@ -27990,6 +28005,7 @@ ${xrefOffset}
|
|
|
27990
28005
|
let endFirstPage = xrefOffset;
|
|
27991
28006
|
const sortedOffsets = [...objectOffsets.entries()].sort((a, b) => a[1].offset - b[1].offset);
|
|
27992
28007
|
for (let i = 0; i < sortedOffsets.length; i++) {
|
|
28008
|
+
if (++work % 16 === 0) yield;
|
|
27993
28009
|
const [objNum, info3] = sortedOffsets[i];
|
|
27994
28010
|
const nextOff = sortedOffsets[i + 1]?.[1].offset ?? xrefOffset;
|
|
27995
28011
|
if (objNum === hintObjAfter.objectNumber) {
|
|
@@ -28023,6 +28039,9 @@ ${xrefOffset}
|
|
|
28023
28039
|
}
|
|
28024
28040
|
return fullBytes;
|
|
28025
28041
|
}
|
|
28042
|
+
function serializeCosDocument(options) {
|
|
28043
|
+
return drainWork(serializeCosDocumentSteps(options));
|
|
28044
|
+
}
|
|
28026
28045
|
function appendIncrementalRevision(originalBytes, doc, updatedObjects) {
|
|
28027
28046
|
const chunks = [originalBytes, textEncoder2.encode("\n")];
|
|
28028
28047
|
let offset = originalBytes.length + 1;
|
|
@@ -28296,48 +28315,30 @@ function encryptPdfBuffer(state, objectNumber, generationNumber, plaintext) {
|
|
|
28296
28315
|
const objKey = md5Bytes([state.fileKey, suffix]).subarray(0, Math.min(16, state.fileKey.length + 5));
|
|
28297
28316
|
return rc4Transform(objKey, plaintext);
|
|
28298
28317
|
}
|
|
28299
|
-
function
|
|
28318
|
+
function* transformNodeStringsAndStreamsSteps(node, transform, transformStream) {
|
|
28319
|
+
yield;
|
|
28300
28320
|
switch (node.kind) {
|
|
28301
28321
|
case "string":
|
|
28302
|
-
return {
|
|
28303
|
-
|
|
28304
|
-
|
|
28305
|
-
|
|
28306
|
-
};
|
|
28307
|
-
|
|
28308
|
-
return {
|
|
28309
|
-
kind: "array",
|
|
28310
|
-
items: node.items.map((item) => transformNodeStringsAndStreams(item, transform, transformStream))
|
|
28311
|
-
};
|
|
28322
|
+
return { kind: "string", format: "hex", bytes: transform(node.bytes) };
|
|
28323
|
+
case "array": {
|
|
28324
|
+
const items = [];
|
|
28325
|
+
for (const item of node.items) items.push(yield* transformNodeStringsAndStreamsSteps(item, transform, transformStream));
|
|
28326
|
+
return { kind: "array", items };
|
|
28327
|
+
}
|
|
28312
28328
|
case "dict": {
|
|
28313
|
-
const type = dictGet(node, "Type");
|
|
28314
|
-
const fieldType = dictGet(node, "FT");
|
|
28315
|
-
const byteRange = dictGet(node, "ByteRange");
|
|
28329
|
+
const type = dictGet(node, "Type"), fieldType = dictGet(node, "FT"), byteRange = dictGet(node, "ByteRange");
|
|
28316
28330
|
const signature = type?.kind === "name" && type.decoded === "Sig" || fieldType?.kind === "name" && fieldType.decoded === "Sig" || byteRange?.kind === "array" && dictGet(node, "Filter")?.kind === "name";
|
|
28317
|
-
|
|
28318
|
-
|
|
28319
|
-
|
|
28320
|
-
key: e.key,
|
|
28321
|
-
value: signature && e.key.decoded === "Contents" ? e.value : transformNodeStringsAndStreams(e.value, transform, transformStream)
|
|
28322
|
-
}))
|
|
28323
|
-
};
|
|
28331
|
+
const entries = [];
|
|
28332
|
+
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) });
|
|
28333
|
+
return { kind: "dict", entries };
|
|
28324
28334
|
}
|
|
28325
28335
|
case "stream": {
|
|
28326
28336
|
const type = dictGet(node.dict, "Type");
|
|
28327
28337
|
if (type?.kind === "name" && type.decoded === "XRef") return node;
|
|
28328
28338
|
const stream = transformStream ? transformStream(node) : { ...node, rawBytes: transform(node.rawBytes) };
|
|
28329
|
-
const
|
|
28330
|
-
|
|
28331
|
-
|
|
28332
|
-
key: e.key,
|
|
28333
|
-
value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : transformNodeStringsAndStreams(e.value, transform, transformStream)
|
|
28334
|
-
}))
|
|
28335
|
-
};
|
|
28336
|
-
return {
|
|
28337
|
-
kind: "stream",
|
|
28338
|
-
dict: updatedDict,
|
|
28339
|
-
rawBytes: stream.rawBytes
|
|
28340
|
-
};
|
|
28339
|
+
const entries = [];
|
|
28340
|
+
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) });
|
|
28341
|
+
return { kind: "stream", dict: { kind: "dict", entries }, rawBytes: stream.rawBytes };
|
|
28341
28342
|
}
|
|
28342
28343
|
default:
|
|
28343
28344
|
return node;
|
|
@@ -28406,7 +28407,8 @@ function createR6Encryption(userPassword, ownerPassword, pMask) {
|
|
|
28406
28407
|
StrF: cosName("StdCF")
|
|
28407
28408
|
}) };
|
|
28408
28409
|
}
|
|
28409
|
-
function
|
|
28410
|
+
function* encryptCosDocumentSteps(doc, options = {}) {
|
|
28411
|
+
yield;
|
|
28410
28412
|
const userPassword = options.userPassword ?? "";
|
|
28411
28413
|
const ownerPassword = options.ownerPassword ?? userPassword;
|
|
28412
28414
|
const revision = options.revision ?? 6;
|
|
@@ -28428,14 +28430,15 @@ function encryptCosDocument(doc, options = {}) {
|
|
|
28428
28430
|
const encryptObjNum = maxObjNum + 1;
|
|
28429
28431
|
const encryptedObjects = [];
|
|
28430
28432
|
for (const obj of doc.objects.values()) {
|
|
28431
|
-
|
|
28433
|
+
yield;
|
|
28434
|
+
const transformed = yield* transformNodeStringsAndStreamsSteps(
|
|
28432
28435
|
obj.value,
|
|
28433
28436
|
(plain) => encryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, plain)
|
|
28434
28437
|
);
|
|
28435
28438
|
encryptedObjects.push({ objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: transformed });
|
|
28436
28439
|
}
|
|
28437
28440
|
encryptedObjects.push({ objectNumber: encryptObjNum, generationNumber: 0, value: encryptDict });
|
|
28438
|
-
return
|
|
28441
|
+
return yield* serializeCosDocumentSteps({
|
|
28439
28442
|
objects: encryptedObjects,
|
|
28440
28443
|
rootRef: doc.rootRef,
|
|
28441
28444
|
infoRef: doc.infoRef,
|
|
@@ -28485,17 +28488,19 @@ function decryptStream(doc, stream, transform) {
|
|
|
28485
28488
|
}
|
|
28486
28489
|
return { kind: "stream", dict, rawBytes: bytes };
|
|
28487
28490
|
}
|
|
28488
|
-
function
|
|
28491
|
+
function* decryptCosDocumentSteps(doc, state) {
|
|
28492
|
+
yield;
|
|
28489
28493
|
const encryptObjNum = doc.encryptRef?.objectNumber;
|
|
28490
28494
|
const handler = securityHandlers.get(state);
|
|
28491
28495
|
for (const [num, obj] of doc.objects.entries()) {
|
|
28496
|
+
yield;
|
|
28492
28497
|
if (num === encryptObjNum || handler?.plaintextObjects.has(num)) continue;
|
|
28493
28498
|
if (obj.value.kind === "stream") {
|
|
28494
28499
|
const type = doc.resolve(dictGet(obj.value.dict, "Type"));
|
|
28495
28500
|
if (type?.kind === "name" && (type.decoded === "XRef" || type.decoded === "Metadata" && !state.encryptMetadata)) continue;
|
|
28496
28501
|
}
|
|
28497
28502
|
const transform = handler?.factory.createCipherTransform(obj.objectNumber, obj.generationNumber);
|
|
28498
|
-
const decrypted =
|
|
28503
|
+
const decrypted = yield* transformNodeStringsAndStreamsSteps(
|
|
28499
28504
|
obj.value,
|
|
28500
28505
|
(cipher) => decryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, cipher),
|
|
28501
28506
|
transform ? (stream) => decryptStream(doc, stream, transform) : void 0
|
|
@@ -28609,9 +28614,12 @@ var ParsedCosDocument = class {
|
|
|
28609
28614
|
return void 0;
|
|
28610
28615
|
}
|
|
28611
28616
|
};
|
|
28612
|
-
function
|
|
28617
|
+
function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
|
|
28618
|
+
yield;
|
|
28619
|
+
let work = 0;
|
|
28613
28620
|
const stack = [];
|
|
28614
28621
|
while (true) {
|
|
28622
|
+
if (++work % 16 === 0) yield;
|
|
28615
28623
|
const tok = lexer.nextToken();
|
|
28616
28624
|
const parent = stack.at(-1);
|
|
28617
28625
|
if (!tok) {
|
|
@@ -28807,7 +28815,8 @@ function parseHeaderVersion(bytes) {
|
|
|
28807
28815
|
}
|
|
28808
28816
|
return head.slice(idx + 5, idx + 8);
|
|
28809
28817
|
}
|
|
28810
|
-
function
|
|
28818
|
+
function* parseObjectAtOffsetSteps(bytes, offset, maxRecursionDepth, repair = false) {
|
|
28819
|
+
yield;
|
|
28811
28820
|
const lexer = new CosByteLexer(bytes, offset);
|
|
28812
28821
|
const objNumTok = lexer.nextToken();
|
|
28813
28822
|
const genNumTok = lexer.nextToken();
|
|
@@ -28815,7 +28824,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
|
|
|
28815
28824
|
if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
|
|
28816
28825
|
throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
|
|
28817
28826
|
}
|
|
28818
|
-
const value =
|
|
28827
|
+
const value = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, repair);
|
|
28819
28828
|
if (!value) {
|
|
28820
28829
|
throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
|
|
28821
28830
|
}
|
|
@@ -28826,7 +28835,9 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
|
|
|
28826
28835
|
span: { start: objNumTok.span.start, end: lexer.offset }
|
|
28827
28836
|
};
|
|
28828
28837
|
}
|
|
28829
|
-
function
|
|
28838
|
+
function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
|
|
28839
|
+
yield;
|
|
28840
|
+
let work = 0;
|
|
28830
28841
|
if (xrefOffset < 0 || xrefOffset >= bytes.length) {
|
|
28831
28842
|
throw new PdfError("E_PARSE", `Invalid xref offset: ${xrefOffset}`);
|
|
28832
28843
|
}
|
|
@@ -28838,6 +28849,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28838
28849
|
if (firstTok.kind === "keyword" && firstTok.value === "xref") {
|
|
28839
28850
|
const entries2 = /* @__PURE__ */ new Map();
|
|
28840
28851
|
while (true) {
|
|
28852
|
+
if (++work % 16 === 0) yield;
|
|
28841
28853
|
const saved = lexer.offset;
|
|
28842
28854
|
const tok = lexer.nextToken();
|
|
28843
28855
|
if (!tok) {
|
|
@@ -28861,6 +28873,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28861
28873
|
}
|
|
28862
28874
|
if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
28863
28875
|
for (let i = 0; i < count; i++) {
|
|
28876
|
+
if (++work % 16 === 0) yield;
|
|
28864
28877
|
const offTok = lexer.nextToken();
|
|
28865
28878
|
const genTok = lexer.nextToken();
|
|
28866
28879
|
const flagTok = lexer.nextToken();
|
|
@@ -28886,7 +28899,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28886
28899
|
if (entries2.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
28887
28900
|
}
|
|
28888
28901
|
}
|
|
28889
|
-
const trailerNode =
|
|
28902
|
+
const trailerNode = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth);
|
|
28890
28903
|
if (!trailerNode || trailerNode.kind !== "dict") {
|
|
28891
28904
|
throw new PdfError("E_PARSE", "Missing trailer dictionary after xref table");
|
|
28892
28905
|
}
|
|
@@ -28898,7 +28911,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28898
28911
|
previousXrefOffset: prevNode2?.kind === "number" ? prevNode2.value : void 0
|
|
28899
28912
|
};
|
|
28900
28913
|
}
|
|
28901
|
-
const xrefObj =
|
|
28914
|
+
const xrefObj = yield* parseObjectAtOffsetSteps(bytes, xrefOffset, maxRecursionDepth);
|
|
28902
28915
|
if (xrefObj.value.kind !== "stream") {
|
|
28903
28916
|
throw new PdfError("E_PARSE", `Expected xref table or XRef stream at offset ${xrefOffset}`);
|
|
28904
28917
|
}
|
|
@@ -28919,6 +28932,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28919
28932
|
if (indexArray) {
|
|
28920
28933
|
if (indexArray.kind !== "array" || indexArray.items.length % 2 !== 0) throw new PdfError("E_PARSE", "Invalid XRef range fields");
|
|
28921
28934
|
for (let i = 0; i < indexArray.items.length; i += 2) {
|
|
28935
|
+
if (++work % 16 === 0) yield;
|
|
28922
28936
|
const first = indexArray.items[i];
|
|
28923
28937
|
const count = indexArray.items[i + 1];
|
|
28924
28938
|
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)) {
|
|
@@ -28941,9 +28955,11 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28941
28955
|
return v;
|
|
28942
28956
|
};
|
|
28943
28957
|
for (const [startObj, count] of subsections) {
|
|
28958
|
+
if (++work % 16 === 0) yield;
|
|
28944
28959
|
if (count > (decoded.length - pos) / stride) throw new PdfError("E_PARSE", "Truncated XRef stream");
|
|
28945
28960
|
if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
28946
28961
|
for (let i = 0; i < count; i++) {
|
|
28962
|
+
if (++work % 16 === 0) yield;
|
|
28947
28963
|
const objNum = startObj + i;
|
|
28948
28964
|
const field0 = w0 > 0 ? readInt(w0) : 1;
|
|
28949
28965
|
const field1 = readInt(w1);
|
|
@@ -28989,12 +29005,16 @@ function isAsciiWhitespace(ch3) {
|
|
|
28989
29005
|
function isAsciiDigit(ch3) {
|
|
28990
29006
|
return ch3 >= 48 && ch3 <= 57;
|
|
28991
29007
|
}
|
|
28992
|
-
function
|
|
29008
|
+
function* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth) {
|
|
29009
|
+
yield;
|
|
29010
|
+
let work = 0;
|
|
28993
29011
|
const objects = /* @__PURE__ */ new Map();
|
|
28994
29012
|
const trailers = [];
|
|
28995
29013
|
let pos = 0;
|
|
28996
29014
|
while (pos < bytes.length) {
|
|
29015
|
+
if (++work % 16 === 0) yield;
|
|
28997
29016
|
while (pos < bytes.length && !isAsciiDigit(bytes[pos])) {
|
|
29017
|
+
if (++work % 16 === 0) yield;
|
|
28998
29018
|
if (bytes[pos] === 37) {
|
|
28999
29019
|
while (pos < bytes.length && bytes[pos] !== 10 && bytes[pos] !== 13) pos++;
|
|
29000
29020
|
continue;
|
|
@@ -29004,7 +29024,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
29004
29024
|
try {
|
|
29005
29025
|
const token = lexer.nextToken();
|
|
29006
29026
|
if (token?.kind === "keyword" && token.value === "trailer") {
|
|
29007
|
-
const trailer =
|
|
29027
|
+
const trailer = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, true);
|
|
29008
29028
|
if (trailer?.kind === "dict") trailers.push(trailer);
|
|
29009
29029
|
pos = lexer.offset;
|
|
29010
29030
|
continue;
|
|
@@ -29037,7 +29057,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
29037
29057
|
bytes[pos + 3] === 40)) {
|
|
29038
29058
|
pos += 3;
|
|
29039
29059
|
try {
|
|
29040
|
-
const parsed =
|
|
29060
|
+
const parsed = yield* parseObjectAtOffsetSteps(bytes, headerStart, maxRecursionDepth, true);
|
|
29041
29061
|
objects.set(parsed.objectNumber, parsed);
|
|
29042
29062
|
if (parsed.value.kind === "stream") {
|
|
29043
29063
|
const type = dictGet(parsed.value.dict, "Type");
|
|
@@ -29054,13 +29074,17 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
29054
29074
|
}
|
|
29055
29075
|
return { objects, trailers };
|
|
29056
29076
|
}
|
|
29057
|
-
function
|
|
29077
|
+
function* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
|
|
29078
|
+
yield;
|
|
29079
|
+
let work = 0;
|
|
29058
29080
|
for (const obj of [...objects.values()]) {
|
|
29081
|
+
if (++work % 16 === 0) yield;
|
|
29059
29082
|
if (obj.value.kind === "stream") {
|
|
29060
29083
|
const t = dictGet(obj.value.dict, "Type");
|
|
29061
29084
|
if (t?.kind === "name" && t.decoded === "ObjStm") {
|
|
29062
29085
|
try {
|
|
29063
|
-
for (const [unpackedNum, unpackedVal] of
|
|
29086
|
+
for (const [unpackedNum, unpackedVal] of (yield* unpackObjectStreamSteps(obj.value, maxDecompressedBytes, maxRecursionDepth, true)).entries()) {
|
|
29087
|
+
if (++work % 16 === 0) yield;
|
|
29064
29088
|
if (!objects.has(unpackedNum)) {
|
|
29065
29089
|
objects.set(unpackedNum, {
|
|
29066
29090
|
objectNumber: unpackedNum,
|
|
@@ -29096,7 +29120,9 @@ function recoveredReferences(objects) {
|
|
|
29096
29120
|
}
|
|
29097
29121
|
return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
|
|
29098
29122
|
}
|
|
29099
|
-
function
|
|
29123
|
+
function* unpackObjectStreamSteps(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
|
|
29124
|
+
yield;
|
|
29125
|
+
let work = 0;
|
|
29100
29126
|
const nNode = dictGet(streamObj.dict, "N");
|
|
29101
29127
|
const firstNode = dictGet(streamObj.dict, "First");
|
|
29102
29128
|
if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
|
|
@@ -29106,6 +29132,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
29106
29132
|
const headerLexer = new CosByteLexer(decoded, 0);
|
|
29107
29133
|
const pairs = [];
|
|
29108
29134
|
for (let i = 0; i < nNode.value; i++) {
|
|
29135
|
+
if (++work % 16 === 0) yield;
|
|
29109
29136
|
const numTok = headerLexer.nextToken();
|
|
29110
29137
|
const offTok = headerLexer.nextToken();
|
|
29111
29138
|
if (numTok?.kind === "number" && offTok?.kind === "number") {
|
|
@@ -29114,9 +29141,10 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
29114
29141
|
}
|
|
29115
29142
|
const result = /* @__PURE__ */ new Map();
|
|
29116
29143
|
for (const pair of pairs) {
|
|
29144
|
+
if (++work % 16 === 0) yield;
|
|
29117
29145
|
try {
|
|
29118
29146
|
const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
|
|
29119
|
-
const node =
|
|
29147
|
+
const node = yield* parseNodeFromLexerSteps(valLexer, decoded, maxRecursionDepth, repair);
|
|
29120
29148
|
if (node) {
|
|
29121
29149
|
result.set(pair.objectNumber, node);
|
|
29122
29150
|
}
|
|
@@ -29126,7 +29154,9 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
29126
29154
|
}
|
|
29127
29155
|
return result;
|
|
29128
29156
|
}
|
|
29129
|
-
function
|
|
29157
|
+
function* parseCosDocumentSteps(bytes, options = {}) {
|
|
29158
|
+
yield;
|
|
29159
|
+
let work = 0;
|
|
29130
29160
|
const version = parseHeaderVersion(bytes);
|
|
29131
29161
|
const recovery = options.recovery ?? "strict";
|
|
29132
29162
|
const maxObjects = options.maxObjects ?? Infinity;
|
|
@@ -29161,10 +29191,12 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29161
29191
|
let currentXrefOffset = offsetTok.value;
|
|
29162
29192
|
const visitedOffsets = /* @__PURE__ */ new Set();
|
|
29163
29193
|
while (currentXrefOffset !== void 0 && !visitedOffsets.has(currentXrefOffset)) {
|
|
29194
|
+
if (++work % 16 === 0) yield;
|
|
29164
29195
|
visitedOffsets.add(currentXrefOffset);
|
|
29165
|
-
const rev =
|
|
29196
|
+
const rev = yield* parseXrefRevisionAtSteps(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
|
|
29166
29197
|
revisions.push(rev);
|
|
29167
29198
|
for (const [num, entry] of rev.entries.entries()) {
|
|
29199
|
+
if (++work % 16 === 0) yield;
|
|
29168
29200
|
if (!mergedXref.has(num)) {
|
|
29169
29201
|
mergedXref.set(num, entry);
|
|
29170
29202
|
if (mergedXref.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
@@ -29197,8 +29229,9 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29197
29229
|
if (!useRepair && rootRef) {
|
|
29198
29230
|
try {
|
|
29199
29231
|
for (const [objNum, entry] of mergedXref.entries()) {
|
|
29232
|
+
if (++work % 16 === 0) yield;
|
|
29200
29233
|
if (entry.type !== "uncompressed") continue;
|
|
29201
|
-
const parsed =
|
|
29234
|
+
const parsed = yield* parseObjectAtOffsetSteps(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
|
|
29202
29235
|
if (parsed.objectNumber !== objNum || parsed.generationNumber !== (entry.generationNumber ?? 0)) {
|
|
29203
29236
|
throw new PdfError("E_PARSE", `Bad uncompressed XRef entry for object ${objNum}`);
|
|
29204
29237
|
}
|
|
@@ -29216,7 +29249,7 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29216
29249
|
throw new PdfError("E_PARSE", "PDF trailer missing /Root reference");
|
|
29217
29250
|
}
|
|
29218
29251
|
useRepair = true;
|
|
29219
|
-
const scanned =
|
|
29252
|
+
const scanned = yield* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth);
|
|
29220
29253
|
objects = scanned.objects;
|
|
29221
29254
|
revisions.length = 0;
|
|
29222
29255
|
mergedXref.clear();
|
|
@@ -29251,7 +29284,7 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29251
29284
|
encryptNode = encrypt?.kind === "ref" || encrypt?.kind === "dict" ? encrypt : void 0;
|
|
29252
29285
|
encryptRef = encrypt?.kind === "ref" ? encrypt : void 0;
|
|
29253
29286
|
idArray = id?.kind === "array" ? id : void 0;
|
|
29254
|
-
if (!rootRef && !encryptNode)
|
|
29287
|
+
if (!rootRef && !encryptNode) yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
|
|
29255
29288
|
const fallback = recoveredReferences(objects);
|
|
29256
29289
|
rootRef ??= fallback.rootRef;
|
|
29257
29290
|
infoRef ??= fallback.infoRef;
|
|
@@ -29286,20 +29319,21 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29286
29319
|
maxRecursionDepth
|
|
29287
29320
|
});
|
|
29288
29321
|
doc.encryption = encState;
|
|
29289
|
-
|
|
29322
|
+
yield* decryptCosDocumentSteps(doc, encState);
|
|
29290
29323
|
}
|
|
29291
29324
|
if (useRepair) {
|
|
29292
|
-
|
|
29325
|
+
yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
|
|
29293
29326
|
doc.infoRef ??= recoveredReferences(objects).infoRef;
|
|
29294
29327
|
}
|
|
29295
29328
|
const objStmCache = /* @__PURE__ */ new Map();
|
|
29296
29329
|
for (const [objNum, entry] of mergedXref.entries()) {
|
|
29330
|
+
if (++work % 16 === 0) yield;
|
|
29297
29331
|
if (entry.type === "compressed" && entry.objectStreamNumber !== void 0) {
|
|
29298
29332
|
let unpacked = objStmCache.get(entry.objectStreamNumber);
|
|
29299
29333
|
if (!unpacked) {
|
|
29300
29334
|
const stmObj = objects.get(entry.objectStreamNumber)?.value;
|
|
29301
29335
|
if (stmObj?.kind === "stream") {
|
|
29302
|
-
unpacked =
|
|
29336
|
+
unpacked = yield* unpackObjectStreamSteps(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
|
|
29303
29337
|
objStmCache.set(entry.objectStreamNumber, unpacked);
|
|
29304
29338
|
}
|
|
29305
29339
|
}
|
|
@@ -29316,6 +29350,9 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29316
29350
|
}
|
|
29317
29351
|
return doc;
|
|
29318
29352
|
}
|
|
29353
|
+
function parseCosDocument(bytes, options = {}) {
|
|
29354
|
+
return drainWork(parseCosDocumentSteps(bytes, options));
|
|
29355
|
+
}
|
|
29319
29356
|
var WIN_ANSI_HIGH_BYTES = {
|
|
29320
29357
|
128: 8364,
|
|
29321
29358
|
130: 8218,
|
|
@@ -40691,7 +40728,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
|
|
|
40691
40728
|
}
|
|
40692
40729
|
return void 0;
|
|
40693
40730
|
}
|
|
40694
|
-
function
|
|
40731
|
+
function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
|
|
40732
|
+
if (++yieldState.work % 256 === 0) yield;
|
|
40695
40733
|
const dict = doc.resolveDict(node);
|
|
40696
40734
|
if (!dict) return out;
|
|
40697
40735
|
const tNode = doc.resolve(dictGet(dict, "T"));
|
|
@@ -40724,7 +40762,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
|
|
|
40724
40762
|
return out;
|
|
40725
40763
|
}
|
|
40726
40764
|
for (const kid of kidsArr.items) {
|
|
40727
|
-
|
|
40765
|
+
if (++yieldState.work % 16 === 0) yield;
|
|
40766
|
+
yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
|
|
40728
40767
|
}
|
|
40729
40768
|
} else if (fullName) {
|
|
40730
40769
|
out.push({
|
|
@@ -41165,6 +41204,9 @@ function escapePdfLiteralString(str) {
|
|
|
41165
41204
|
}
|
|
41166
41205
|
return out;
|
|
41167
41206
|
}
|
|
41207
|
+
function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
|
|
41208
|
+
drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
|
|
41209
|
+
}
|
|
41168
41210
|
var PdfPage = class {
|
|
41169
41211
|
cosDoc;
|
|
41170
41212
|
pageRef;
|
|
@@ -43845,14 +43887,18 @@ var PdfDocument = class _PdfDocument {
|
|
|
43845
43887
|
});
|
|
43846
43888
|
return new _PdfDocument(parseCosDocument(rawBytes));
|
|
43847
43889
|
}
|
|
43848
|
-
static
|
|
43890
|
+
static *loadSteps(bytes, options) {
|
|
43891
|
+
yield;
|
|
43849
43892
|
return new _PdfDocument(
|
|
43850
|
-
|
|
43893
|
+
yield* parseCosDocumentSteps(bytes, {
|
|
43851
43894
|
...options,
|
|
43852
43895
|
recovery: options?.recovery ?? "repair"
|
|
43853
43896
|
})
|
|
43854
43897
|
);
|
|
43855
43898
|
}
|
|
43899
|
+
static load(bytes, options) {
|
|
43900
|
+
return drainWork(_PdfDocument.loadSteps(bytes, options));
|
|
43901
|
+
}
|
|
43856
43902
|
rebuildPagesList() {
|
|
43857
43903
|
const catalog = this.cos.resolveDict(this.cos.rootRef);
|
|
43858
43904
|
const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
|
|
@@ -43934,20 +43980,30 @@ var PdfDocument = class _PdfDocument {
|
|
|
43934
43980
|
this.pages.splice(index, 1);
|
|
43935
43981
|
this.syncPageTree();
|
|
43936
43982
|
}
|
|
43937
|
-
|
|
43983
|
+
*copyPagesFromSteps(sourceDoc, indices) {
|
|
43984
|
+
function* cloneItems(items) {
|
|
43985
|
+
const result = [];
|
|
43986
|
+
for (const item of items) result.push(yield* cloneNode(item));
|
|
43987
|
+
return result;
|
|
43988
|
+
}
|
|
43989
|
+
yield;
|
|
43990
|
+
let work = 0;
|
|
43938
43991
|
const memo = /* @__PURE__ */ new Map();
|
|
43939
43992
|
const sourcePageObjNums = /* @__PURE__ */ new Set();
|
|
43940
43993
|
for (let i = 0; i < sourceDoc.getPageCount(); i++) {
|
|
43994
|
+
if (++work % 16 === 0) yield;
|
|
43941
43995
|
sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
|
|
43942
43996
|
}
|
|
43943
43997
|
const targetPageRefs = [];
|
|
43944
43998
|
for (const idx of indices) {
|
|
43999
|
+
if (++work % 16 === 0) yield;
|
|
43945
44000
|
const srcPage = sourceDoc.getPage(idx);
|
|
43946
44001
|
const pageRef = this.cos.allocateObject({ kind: "null" });
|
|
43947
44002
|
targetPageRefs.push(pageRef);
|
|
43948
44003
|
memo.set(srcPage.ref.objectNumber, pageRef);
|
|
43949
44004
|
}
|
|
43950
|
-
const cloneNode = (node)
|
|
44005
|
+
const cloneNode = function* (node) {
|
|
44006
|
+
if (++work % 16 === 0) yield;
|
|
43951
44007
|
if (node.kind === "ref") {
|
|
43952
44008
|
const existing = memo.get(node.objectNumber);
|
|
43953
44009
|
if (existing) return existing;
|
|
@@ -43958,12 +44014,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
43958
44014
|
if (!target) return cosRef(0);
|
|
43959
44015
|
const placeholderRef = this.cos.allocateObject({ kind: "null" });
|
|
43960
44016
|
memo.set(node.objectNumber, placeholderRef);
|
|
43961
|
-
const clonedTarget = cloneNode(target);
|
|
44017
|
+
const clonedTarget = yield* cloneNode(target);
|
|
43962
44018
|
this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
|
|
43963
44019
|
return placeholderRef;
|
|
43964
44020
|
}
|
|
43965
44021
|
if (node.kind === "array") {
|
|
43966
|
-
return cosArray(node.items
|
|
44022
|
+
return cosArray(yield* cloneItems(node.items));
|
|
43967
44023
|
}
|
|
43968
44024
|
if (node.kind === "dict") {
|
|
43969
44025
|
const typeEntry = dictGet(node, "Type");
|
|
@@ -43973,13 +44029,13 @@ var PdfDocument = class _PdfDocument {
|
|
|
43973
44029
|
if (isPageTreeNode && entry.key.decoded === "Parent") continue;
|
|
43974
44030
|
newEntries.push({
|
|
43975
44031
|
key: { ...entry.key },
|
|
43976
|
-
value: cloneNode(entry.value)
|
|
44032
|
+
value: yield* cloneNode(entry.value)
|
|
43977
44033
|
});
|
|
43978
44034
|
}
|
|
43979
44035
|
return { kind: "dict", entries: newEntries };
|
|
43980
44036
|
}
|
|
43981
44037
|
if (node.kind === "stream") {
|
|
43982
|
-
const clonedDict = cloneNode(node.dict);
|
|
44038
|
+
const clonedDict = yield* cloneNode(node.dict);
|
|
43983
44039
|
return {
|
|
43984
44040
|
kind: "stream",
|
|
43985
44041
|
dict: clonedDict,
|
|
@@ -43988,11 +44044,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
43988
44044
|
};
|
|
43989
44045
|
}
|
|
43990
44046
|
return node;
|
|
43991
|
-
};
|
|
44047
|
+
}.bind(this);
|
|
43992
44048
|
const copiedPages = [];
|
|
43993
44049
|
for (const [position, idx] of indices.entries()) {
|
|
44050
|
+
if (++work % 16 === 0) yield;
|
|
43994
44051
|
const srcPage = sourceDoc.getPage(idx);
|
|
43995
|
-
const clonedPageDict = cloneNode(srcPage.pageDict);
|
|
44052
|
+
const clonedPageDict = yield* cloneNode(srcPage.pageDict);
|
|
43996
44053
|
const size = srcPage.getSize();
|
|
43997
44054
|
if (!dictGet(clonedPageDict, "MediaBox")) {
|
|
43998
44055
|
dictSet(
|
|
@@ -44002,13 +44059,14 @@ var PdfDocument = class _PdfDocument {
|
|
|
44002
44059
|
);
|
|
44003
44060
|
}
|
|
44004
44061
|
if (!dictGet(clonedPageDict, "Resources")) {
|
|
44005
|
-
dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
|
|
44062
|
+
dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
|
|
44006
44063
|
}
|
|
44007
44064
|
if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
|
|
44008
44065
|
dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
|
|
44009
44066
|
}
|
|
44010
44067
|
const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
|
|
44011
44068
|
for (const boxKey of inheritedBoxKeys) {
|
|
44069
|
+
if (++work % 16 === 0) yield;
|
|
44012
44070
|
if (!dictGet(clonedPageDict, boxKey)) {
|
|
44013
44071
|
const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
|
|
44014
44072
|
if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
|
|
@@ -44050,8 +44108,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
44050
44108
|
};
|
|
44051
44109
|
const clonedRootFieldRefs = [];
|
|
44052
44110
|
for (const item of srcFieldsArr.items) {
|
|
44111
|
+
if (++work % 16 === 0) yield;
|
|
44053
44112
|
if (!hasClonedDescendant(item)) continue;
|
|
44054
|
-
const cloned = cloneNode(item);
|
|
44113
|
+
const cloned = yield* cloneNode(item);
|
|
44055
44114
|
if (cloned.kind === "ref") {
|
|
44056
44115
|
const clonedDict = this.cos.resolveDict(cloned);
|
|
44057
44116
|
const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
|
|
@@ -44085,6 +44144,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
44085
44144
|
dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
|
|
44086
44145
|
);
|
|
44087
44146
|
for (const fRef of clonedRootFieldRefs) {
|
|
44147
|
+
if (++work % 16 === 0) yield;
|
|
44088
44148
|
if (!existingNums.has(fRef.objectNumber)) {
|
|
44089
44149
|
dstFields.items.push(fRef);
|
|
44090
44150
|
existingNums.add(fRef.objectNumber);
|
|
@@ -44092,11 +44152,11 @@ var PdfDocument = class _PdfDocument {
|
|
|
44092
44152
|
}
|
|
44093
44153
|
const srcDr = dictGet(srcAcroForm, "DR");
|
|
44094
44154
|
if (srcDr && !dictGet(dstAcroForm, "DR")) {
|
|
44095
|
-
dictSet(dstAcroForm, "DR", cloneNode(srcDr));
|
|
44155
|
+
dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
|
|
44096
44156
|
}
|
|
44097
44157
|
const srcDa = dictGet(srcAcroForm, "DA");
|
|
44098
44158
|
if (srcDa && !dictGet(dstAcroForm, "DA")) {
|
|
44099
|
-
dictSet(dstAcroForm, "DA", cloneNode(srcDa));
|
|
44159
|
+
dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
|
|
44100
44160
|
}
|
|
44101
44161
|
}
|
|
44102
44162
|
}
|
|
@@ -44105,12 +44165,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
44105
44165
|
if (srcOcProps) {
|
|
44106
44166
|
const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
|
|
44107
44167
|
if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
|
|
44108
|
-
dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
|
|
44168
|
+
dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
|
|
44109
44169
|
}
|
|
44110
44170
|
}
|
|
44111
44171
|
this.syncPageTree();
|
|
44112
44172
|
return copiedPages;
|
|
44113
44173
|
}
|
|
44174
|
+
copyPagesFrom(sourceDoc, indices) {
|
|
44175
|
+
return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
|
|
44176
|
+
}
|
|
44114
44177
|
embedStandardFont(fontName) {
|
|
44115
44178
|
return createStandardFontHandle(fontName);
|
|
44116
44179
|
}
|
|
@@ -44310,14 +44373,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
44310
44373
|
});
|
|
44311
44374
|
return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
|
|
44312
44375
|
}
|
|
44313
|
-
|
|
44376
|
+
*saveSteps(options = {}) {
|
|
44377
|
+
yield;
|
|
44314
44378
|
this.syncPageTree();
|
|
44315
44379
|
if (this.cos.requiresFullRewrite) {
|
|
44316
44380
|
pruneUnusedXObjects(this.cos, this.pages);
|
|
44317
44381
|
discardUnreachableObjects(this.cos);
|
|
44318
44382
|
}
|
|
44319
44383
|
if (options.encrypt) {
|
|
44320
|
-
return
|
|
44384
|
+
return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
|
|
44321
44385
|
}
|
|
44322
44386
|
const allObjects = [...this.cos.objects.values()].sort(
|
|
44323
44387
|
(a, b) => a.objectNumber - b.objectNumber
|
|
@@ -44325,7 +44389,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
44325
44389
|
if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
|
|
44326
44390
|
return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
|
|
44327
44391
|
}
|
|
44328
|
-
return
|
|
44392
|
+
return yield* serializeCosDocumentSteps({
|
|
44329
44393
|
objects: allObjects,
|
|
44330
44394
|
rootRef: this.cos.rootRef,
|
|
44331
44395
|
infoRef: this.cos.infoRef,
|
|
@@ -44336,6 +44400,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
44336
44400
|
linearize: options.linearize
|
|
44337
44401
|
});
|
|
44338
44402
|
}
|
|
44403
|
+
save(options = {}) {
|
|
44404
|
+
return drainWork(this.saveSteps(options));
|
|
44405
|
+
}
|
|
44339
44406
|
};
|
|
44340
44407
|
function resolveDestinationPageIndex(doc, destOrActionNode) {
|
|
44341
44408
|
const cos = doc.cos;
|