@poe-platform/safe-bash 0.1.758 → 0.1.760

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.
Files changed (33) hide show
  1. package/dist/image-ast/index.browser.js +41 -16
  2. package/dist/image-ast/index.js +41 -16
  3. package/dist/pdf-ast/ast.d.ts +8 -3
  4. package/dist/pdf-ast/index.js +45 -19
  5. package/dist/safe-bash/chunks/{chunk-WNWIBBJZ.js → chunk-CRQDMBQA.js} +130 -9
  6. package/dist/safe-bash/command-chunks/{chunk-L2C5TIII.js → chunk-MC4XXPQJ.js} +2 -2
  7. package/dist/safe-bash/command-chunks/{chunk-TCAGGM44.js → chunk-S3SCPBHC.js} +41 -17
  8. package/dist/safe-bash/command-chunks/{chunk-XYCWDGOG.js → chunk-UCI6ZQFB.js} +1 -1
  9. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  10. package/dist/safe-bash/commands/python/index.d.ts +1 -1
  11. package/dist/safe-bash/commands/python/llm-capability.d.ts +7 -3
  12. package/dist/safe-bash/commands/python/llm-capability.js +149 -10
  13. package/dist/safe-bash/commands/python/shell-capability.js +10 -2
  14. package/dist/safe-bash/core.browser.js +1 -1
  15. package/dist/safe-bash-command-ffmpeg/index.js +3513 -3500
  16. package/dist/safe-bash-command-gh/index.js +128 -27
  17. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  18. package/dist/safe-bash-command-pandoc/command.js +3 -3
  19. package/dist/safe-bash-command-pandoc/index.js +3 -3
  20. package/dist/safe-bash-command-pdfimages/index.js +41 -16
  21. package/dist/safe-bash-command-pdfinfo/index.js +45 -19
  22. package/dist/safe-bash-command-pdftk/index.js +41 -16
  23. package/dist/safe-bash-command-pdftoppm/index.js +45 -19
  24. package/dist/safe-bash-command-pdftotext/index.js +41 -16
  25. package/dist/safe-bash-command-qpdf/index.js +41 -16
  26. package/dist/safe-bash-command-sips/index.js +2 -2
  27. package/dist/safe-bash-command-soffice/index.js +1 -1
  28. package/dist/safe-bash-command-ssconvert/index.js +63 -38
  29. package/dist/safe-bash-command-wkhtmltopdf/index.js +42 -16
  30. package/dist/safe-bash-io-engine/internal.d.ts +2 -2
  31. package/dist/safe-bash-mcp/index.d.ts +1 -1
  32. package/package.json +2 -2
  33. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +22 -0
@@ -656,6 +656,7 @@ var messages_default = {
656
656
  "-5": "buffer error",
657
657
  "-6": "incompatible version"
658
658
  };
659
+ var Z_BUF_ERROR = -5;
659
660
  var MAX_MEM_LEVEL = 9;
660
661
  var HEAP_SIZE = 573;
661
662
  var MIN_MATCH = 3;
@@ -22547,22 +22548,31 @@ function decodeFlate(bytes, parms, maxDecodedBytes = DEFAULT_MAX_DECODED_BYTES)
22547
22548
  inflated = new BoundedFlateStream(bytes, maxDecodedBytes).getBytes();
22548
22549
  } catch (error) {
22549
22550
  if (error instanceof PdfError && error.code === "E_LIMIT") throw error;
22551
+ const wrapped = bytes[0] === 31 && bytes[1] === 139 || bytes.length >= 2 && (bytes[0] & 15) === 8 && bytes[0] >>> 4 <= 7 && (bytes[0] << 8 | bytes[1]) % 31 === 0;
22550
22552
  const decoder = new Inflate({
22551
- raw: !(bytes[0] === 31 && bytes[1] === 139),
22553
+ raw: !wrapped,
22552
22554
  chunkSize: Math.max(1, Math.min(64 * 1024, maxDecodedBytes + 1))
22553
22555
  });
22556
+ const chunks = [];
22554
22557
  let length = 0;
22555
22558
  decoder.onData = (chunk) => {
22556
22559
  length += chunk.length;
22557
22560
  if (length > maxDecodedBytes) {
22558
22561
  throw new PdfError("E_LIMIT", "FlateDecode output exceeds maximum decoded byte budget");
22559
22562
  }
22560
- decoder.chunks.push(chunk);
22563
+ chunks.push(chunk);
22561
22564
  };
22562
- if (!decoder.push(bytes, true) || decoder.err || !decoder.ended) {
22565
+ const complete = decoder.push(bytes, true);
22566
+ const truncated = wrapped && decoder.err === Z_BUF_ERROR && length > 0;
22567
+ if ((!complete || decoder.err || !decoder.ended) && !truncated) {
22563
22568
  throw new PdfError("E_CAPABILITY", "Invalid FlateDecode compressed stream");
22564
22569
  }
22565
- inflated = decoder.result;
22570
+ inflated = new Uint8Array(length);
22571
+ let offset = 0;
22572
+ for (const chunk of chunks) {
22573
+ inflated.set(chunk, offset);
22574
+ offset += chunk.length;
22575
+ }
22566
22576
  }
22567
22577
  return applyPredictor(inflated, parms);
22568
22578
  }
@@ -34451,7 +34461,7 @@ function resolvePageFonts(doc, resourcesDict) {
34451
34461
  const glyphNames = buildFontEncodingGlyphNamesMap(encNode);
34452
34462
  const widths = /* @__PURE__ */ new Map();
34453
34463
  let defaultWidth = 556;
34454
- const isTwoByteCid = subtype === "Type0" || Boolean(cmap?.isTwoByte);
34464
+ const isTwoByteCid = subtype === "Type0";
34455
34465
  let fontMatrix;
34456
34466
  let charProcs;
34457
34467
  let fontResources;
@@ -35904,7 +35914,7 @@ function evaluateContentStreamToDisplayList(params) {
35904
35914
  const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
35905
35915
  transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
35906
35916
  } else if (seg.kind === "rect") {
35907
- if (hasRotOrShear) {
35917
+ if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
35908
35918
  const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
35909
35919
  const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
35910
35920
  const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
@@ -35937,7 +35947,12 @@ function evaluateContentStreamToDisplayList(params) {
35937
35947
  transformedSegments.push({ kind: "close" });
35938
35948
  }
35939
35949
  }
35940
- if (node.clip && transformedSegments.length > 0) {
35950
+ const applyClip = () => {
35951
+ if (!node.clip) return;
35952
+ st.clipPaths = [...st.clipPaths ?? [], {
35953
+ segments: transformedSegments,
35954
+ fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
35955
+ }];
35941
35956
  let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
35942
35957
  for (const s of transformedSegments) {
35943
35958
  if (s.kind === "move" || s.kind === "line") {
@@ -35965,8 +35980,11 @@ function evaluateContentStreamToDisplayList(params) {
35965
35980
  Math.min(st.clipRect[3], cMaxY)
35966
35981
  ] : [cMinX, cMinY, cMaxX, cMaxY];
35967
35982
  }
35983
+ };
35984
+ if (node.paint === "n") {
35985
+ applyClip();
35986
+ break;
35968
35987
  }
35969
- if (node.paint === "n") break;
35970
35988
  const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
35971
35989
  const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
35972
35990
  let evaluatedFillPattern = false;
@@ -36099,7 +36117,10 @@ function evaluateContentStreamToDisplayList(params) {
36099
36117
  }
36100
36118
  }
36101
36119
  }
36102
- if (evaluatedFillPattern && !isStroke) break;
36120
+ if (evaluatedFillPattern && !isStroke) {
36121
+ applyClip();
36122
+ break;
36123
+ }
36103
36124
  const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
36104
36125
  const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
36105
36126
  const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
@@ -36119,6 +36140,7 @@ function evaluateContentStreamToDisplayList(params) {
36119
36140
  ...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
36120
36141
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
36121
36142
  } });
36143
+ applyClip();
36122
36144
  break;
36123
36145
  }
36124
36146
  case "xobject": {
@@ -39552,8 +39574,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
39552
39574
  if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
39553
39575
  edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
39554
39576
  }
39555
- const [rx0, ry0] = toScreen(seg.x, seg.y + seg.height);
39556
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
39577
+ const [rx0, ry0] = toScreen(seg.x, seg.y);
39578
+ const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
39557
39579
  edges.push(
39558
39580
  { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
39559
39581
  { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
@@ -39696,21 +39718,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
39696
39718
  }
39697
39719
  const aaVec = options.antialiasVector !== false;
39698
39720
  const aaTxt = options.antialiasText !== false;
39699
- const clipMasks = /* @__PURE__ */ new Map();
39721
+ let cachedClips;
39722
+ let cachedClipMask;
39700
39723
  const imageClipMasks = /* @__PURE__ */ new Map();
39701
39724
  for (const original of paintOperations(displayList)) {
39702
39725
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
39703
39726
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
39704
39727
  const clips = original.value.clipPaths;
39705
- let clipMask = clips ? clipMasks.get(clips) : void 0;
39728
+ let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
39706
39729
  if (clips && !clipMask) {
39707
39730
  clipMask = new Uint8Array(width * height * 4).fill(255);
39708
- for (const segments of clips) {
39731
+ for (const clip of clips) {
39732
+ const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
39709
39733
  const layer = new Uint8Array(width * height * 4);
39710
- fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
39734
+ fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
39711
39735
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
39712
39736
  }
39713
- clipMasks.set(clips, clipMask);
39737
+ cachedClips = clips;
39738
+ cachedClipMask = clipMask;
39714
39739
  }
39715
39740
  const imageClips = original.value.clipImages;
39716
39741
  if (imageClips) {
@@ -11,8 +11,8 @@ import {
11
11
  readImageMetadata,
12
12
  resizeImage,
13
13
  rotateImage
14
- } from "../safe-bash/command-chunks/chunk-XYCWDGOG.js";
15
- import "../safe-bash/command-chunks/chunk-TCAGGM44.js";
14
+ } from "../safe-bash/command-chunks/chunk-UCI6ZQFB.js";
15
+ import "../safe-bash/command-chunks/chunk-S3SCPBHC.js";
16
16
  import {
17
17
  init_buffer
18
18
  } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -31,7 +31,7 @@ import {
31
31
  PdfDocument,
32
32
  decodeFlate,
33
33
  rgb
34
- } from "../safe-bash/command-chunks/chunk-TCAGGM44.js";
34
+ } from "../safe-bash/command-chunks/chunk-S3SCPBHC.js";
35
35
  import {
36
36
  init_buffer
37
37
  } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -1778,7 +1778,7 @@ var require_deflate = __commonJS({
1778
1778
  var Z_STREAM_END2 = 1;
1779
1779
  var Z_STREAM_ERROR = -2;
1780
1780
  var Z_DATA_ERROR2 = -3;
1781
- var Z_BUF_ERROR2 = -5;
1781
+ var Z_BUF_ERROR3 = -5;
1782
1782
  var Z_DEFAULT_COMPRESSION = -1;
1783
1783
  var Z_FILTERED = 1;
1784
1784
  var Z_HUFFMAN_ONLY = 2;
@@ -2476,7 +2476,7 @@ var require_deflate = __commonJS({
2476
2476
  }
2477
2477
  s = strm.state;
2478
2478
  if (!strm.output || !strm.input && strm.avail_in !== 0 || s.status === FINISH_STATE3 && flush !== Z_FINISH2) {
2479
- return err3(strm, strm.avail_out === 0 ? Z_BUF_ERROR2 : Z_STREAM_ERROR);
2479
+ return err3(strm, strm.avail_out === 0 ? Z_BUF_ERROR3 : Z_STREAM_ERROR);
2480
2480
  }
2481
2481
  s.strm = strm;
2482
2482
  old_flush = s.last_flush;
@@ -2658,10 +2658,10 @@ var require_deflate = __commonJS({
2658
2658
  return Z_OK2;
2659
2659
  }
2660
2660
  } else if (strm.avail_in === 0 && rank3(flush) <= rank3(old_flush) && flush !== Z_FINISH2) {
2661
- return err3(strm, Z_BUF_ERROR2);
2661
+ return err3(strm, Z_BUF_ERROR3);
2662
2662
  }
2663
2663
  if (s.status === FINISH_STATE3 && strm.avail_in !== 0) {
2664
- return err3(strm, Z_BUF_ERROR2);
2664
+ return err3(strm, Z_BUF_ERROR3);
2665
2665
  }
2666
2666
  if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH2 && s.status !== FINISH_STATE3) {
2667
2667
  var bstate = s.strategy === Z_HUFFMAN_ONLY ? deflate_huff3(s, flush) : s.strategy === Z_RLE ? deflate_rle3(s, flush) : configuration_table3[s.level].func(s, flush);
@@ -3688,7 +3688,7 @@ var require_inflate = __commonJS({
3688
3688
  var Z_STREAM_ERROR = -2;
3689
3689
  var Z_DATA_ERROR2 = -3;
3690
3690
  var Z_MEM_ERROR = -4;
3691
- var Z_BUF_ERROR2 = -5;
3691
+ var Z_BUF_ERROR3 = -5;
3692
3692
  var Z_DEFLATED = 8;
3693
3693
  var HEAD3 = 1;
3694
3694
  var FLAGS3 = 2;
@@ -4838,7 +4838,7 @@ var require_inflate = __commonJS({
4838
4838
  }
4839
4839
  strm.data_type = state.bits + (state.last ? 64 : 0) + (state.mode === TYPE3 ? 128 : 0) + (state.mode === LEN_3 || state.mode === COPY_3 ? 256 : 0);
4840
4840
  if ((_in === 0 && _out === 0 || flush === Z_FINISH2) && ret === Z_OK2) {
4841
- ret = Z_BUF_ERROR2;
4841
+ ret = Z_BUF_ERROR3;
4842
4842
  }
4843
4843
  return ret;
4844
4844
  }
@@ -7049,7 +7049,7 @@ var require_deflate3 = __commonJS({
7049
7049
  var Z_STREAM_END2 = 1;
7050
7050
  var Z_STREAM_ERROR = -2;
7051
7051
  var Z_DATA_ERROR2 = -3;
7052
- var Z_BUF_ERROR2 = -5;
7052
+ var Z_BUF_ERROR3 = -5;
7053
7053
  var Z_DEFAULT_COMPRESSION = -1;
7054
7054
  var Z_FILTERED = 1;
7055
7055
  var Z_HUFFMAN_ONLY = 2;
@@ -7747,7 +7747,7 @@ var require_deflate3 = __commonJS({
7747
7747
  }
7748
7748
  s = strm.state;
7749
7749
  if (!strm.output || !strm.input && strm.avail_in !== 0 || s.status === FINISH_STATE3 && flush !== Z_FINISH2) {
7750
- return err3(strm, strm.avail_out === 0 ? Z_BUF_ERROR2 : Z_STREAM_ERROR);
7750
+ return err3(strm, strm.avail_out === 0 ? Z_BUF_ERROR3 : Z_STREAM_ERROR);
7751
7751
  }
7752
7752
  s.strm = strm;
7753
7753
  old_flush = s.last_flush;
@@ -7929,10 +7929,10 @@ var require_deflate3 = __commonJS({
7929
7929
  return Z_OK2;
7930
7930
  }
7931
7931
  } else if (strm.avail_in === 0 && rank3(flush) <= rank3(old_flush) && flush !== Z_FINISH2) {
7932
- return err3(strm, Z_BUF_ERROR2);
7932
+ return err3(strm, Z_BUF_ERROR3);
7933
7933
  }
7934
7934
  if (s.status === FINISH_STATE3 && strm.avail_in !== 0) {
7935
- return err3(strm, Z_BUF_ERROR2);
7935
+ return err3(strm, Z_BUF_ERROR3);
7936
7936
  }
7937
7937
  if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH2 && s.status !== FINISH_STATE3) {
7938
7938
  var bstate = s.strategy === Z_HUFFMAN_ONLY ? deflate_huff3(s, flush) : s.strategy === Z_RLE ? deflate_rle3(s, flush) : configuration_table3[s.level].func(s, flush);
@@ -8959,7 +8959,7 @@ var require_inflate3 = __commonJS({
8959
8959
  var Z_STREAM_ERROR = -2;
8960
8960
  var Z_DATA_ERROR2 = -3;
8961
8961
  var Z_MEM_ERROR = -4;
8962
- var Z_BUF_ERROR2 = -5;
8962
+ var Z_BUF_ERROR3 = -5;
8963
8963
  var Z_DEFLATED = 8;
8964
8964
  var HEAD3 = 1;
8965
8965
  var FLAGS3 = 2;
@@ -10109,7 +10109,7 @@ var require_inflate3 = __commonJS({
10109
10109
  }
10110
10110
  strm.data_type = state.bits + (state.last ? 64 : 0) + (state.mode === TYPE3 ? 128 : 0) + (state.mode === LEN_3 || state.mode === COPY_3 ? 256 : 0);
10111
10111
  if ((_in === 0 && _out === 0 || flush === Z_FINISH2) && ret === Z_OK2) {
10112
- ret = Z_BUF_ERROR2;
10112
+ ret = Z_BUF_ERROR3;
10113
10113
  }
10114
10114
  return ret;
10115
10115
  }
@@ -14564,7 +14564,7 @@ var require_deflate5 = __commonJS({
14564
14564
  var Z_STREAM_END2 = 1;
14565
14565
  var Z_STREAM_ERROR = -2;
14566
14566
  var Z_DATA_ERROR2 = -3;
14567
- var Z_BUF_ERROR2 = -5;
14567
+ var Z_BUF_ERROR3 = -5;
14568
14568
  var Z_DEFAULT_COMPRESSION = -1;
14569
14569
  var Z_FILTERED = 1;
14570
14570
  var Z_HUFFMAN_ONLY = 2;
@@ -15262,7 +15262,7 @@ var require_deflate5 = __commonJS({
15262
15262
  }
15263
15263
  s = strm.state;
15264
15264
  if (!strm.output || !strm.input && strm.avail_in !== 0 || s.status === FINISH_STATE3 && flush !== Z_FINISH2) {
15265
- return err3(strm, strm.avail_out === 0 ? Z_BUF_ERROR2 : Z_STREAM_ERROR);
15265
+ return err3(strm, strm.avail_out === 0 ? Z_BUF_ERROR3 : Z_STREAM_ERROR);
15266
15266
  }
15267
15267
  s.strm = strm;
15268
15268
  old_flush = s.last_flush;
@@ -15444,10 +15444,10 @@ var require_deflate5 = __commonJS({
15444
15444
  return Z_OK2;
15445
15445
  }
15446
15446
  } else if (strm.avail_in === 0 && rank3(flush) <= rank3(old_flush) && flush !== Z_FINISH2) {
15447
- return err3(strm, Z_BUF_ERROR2);
15447
+ return err3(strm, Z_BUF_ERROR3);
15448
15448
  }
15449
15449
  if (s.status === FINISH_STATE3 && strm.avail_in !== 0) {
15450
- return err3(strm, Z_BUF_ERROR2);
15450
+ return err3(strm, Z_BUF_ERROR3);
15451
15451
  }
15452
15452
  if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH2 && s.status !== FINISH_STATE3) {
15453
15453
  var bstate = s.strategy === Z_HUFFMAN_ONLY ? deflate_huff3(s, flush) : s.strategy === Z_RLE ? deflate_rle3(s, flush) : configuration_table3[s.level].func(s, flush);
@@ -16474,7 +16474,7 @@ var require_inflate5 = __commonJS({
16474
16474
  var Z_STREAM_ERROR = -2;
16475
16475
  var Z_DATA_ERROR2 = -3;
16476
16476
  var Z_MEM_ERROR = -4;
16477
- var Z_BUF_ERROR2 = -5;
16477
+ var Z_BUF_ERROR3 = -5;
16478
16478
  var Z_DEFLATED = 8;
16479
16479
  var HEAD3 = 1;
16480
16480
  var FLAGS3 = 2;
@@ -17624,7 +17624,7 @@ var require_inflate5 = __commonJS({
17624
17624
  }
17625
17625
  strm.data_type = state.bits + (state.last ? 64 : 0) + (state.mode === TYPE3 ? 128 : 0) + (state.mode === LEN_3 || state.mode === COPY_3 ? 256 : 0);
17626
17626
  if ((_in === 0 && _out === 0 || flush === Z_FINISH2) && ret === Z_OK2) {
17627
- ret = Z_BUF_ERROR2;
17627
+ ret = Z_BUF_ERROR3;
17628
17628
  }
17629
17629
  return ret;
17630
17630
  }
@@ -51584,7 +51584,7 @@ var require_fontkit_umd = __commonJS({
51584
51584
  var Z_STREAM_END2 = 1;
51585
51585
  var Z_STREAM_ERROR = -2;
51586
51586
  var Z_DATA_ERROR2 = -3;
51587
- var Z_BUF_ERROR2 = -5;
51587
+ var Z_BUF_ERROR3 = -5;
51588
51588
  var Z_DEFAULT_COMPRESSION = -1;
51589
51589
  var Z_FILTERED = 1;
51590
51590
  var Z_HUFFMAN_ONLY = 2;
@@ -52282,7 +52282,7 @@ var require_fontkit_umd = __commonJS({
52282
52282
  }
52283
52283
  s = strm.state;
52284
52284
  if (!strm.output || !strm.input && strm.avail_in !== 0 || s.status === FINISH_STATE3 && flush !== Z_FINISH2) {
52285
- return err3(strm, strm.avail_out === 0 ? Z_BUF_ERROR2 : Z_STREAM_ERROR);
52285
+ return err3(strm, strm.avail_out === 0 ? Z_BUF_ERROR3 : Z_STREAM_ERROR);
52286
52286
  }
52287
52287
  s.strm = strm;
52288
52288
  old_flush = s.last_flush;
@@ -52461,10 +52461,10 @@ var require_fontkit_umd = __commonJS({
52461
52461
  return Z_OK2;
52462
52462
  }
52463
52463
  } else if (strm.avail_in === 0 && rank3(flush) <= rank3(old_flush) && flush !== Z_FINISH2) {
52464
- return err3(strm, Z_BUF_ERROR2);
52464
+ return err3(strm, Z_BUF_ERROR3);
52465
52465
  }
52466
52466
  if (s.status === FINISH_STATE3 && strm.avail_in !== 0) {
52467
- return err3(strm, Z_BUF_ERROR2);
52467
+ return err3(strm, Z_BUF_ERROR3);
52468
52468
  }
52469
52469
  if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH2 && s.status !== FINISH_STATE3) {
52470
52470
  var bstate = s.strategy === Z_HUFFMAN_ONLY ? deflate_huff3(s, flush) : s.strategy === Z_RLE ? deflate_rle3(s, flush) : configuration_table3[s.level].func(s, flush);
@@ -174163,6 +174163,7 @@ var messages_default22 = {
174163
174163
  "-5": "buffer error",
174164
174164
  "-6": "incompatible version"
174165
174165
  };
174166
+ var Z_BUF_ERROR2 = -5;
174166
174167
  var MAX_MEM_LEVEL22 = 9;
174167
174168
  var HEAP_SIZE22 = 573;
174168
174169
  var MIN_MATCH22 = 3;
@@ -196054,22 +196055,31 @@ function decodeFlate(bytes, parms, maxDecodedBytes = DEFAULT_MAX_DECODED_BYTES)
196054
196055
  inflated = new BoundedFlateStream(bytes, maxDecodedBytes).getBytes();
196055
196056
  } catch (error2) {
196056
196057
  if (error2 instanceof PdfError2 && error2.code === "E_LIMIT") throw error2;
196058
+ const wrapped = bytes[0] === 31 && bytes[1] === 139 || bytes.length >= 2 && (bytes[0] & 15) === 8 && bytes[0] >>> 4 <= 7 && (bytes[0] << 8 | bytes[1]) % 31 === 0;
196057
196059
  const decoder2 = new Inflate22({
196058
- raw: !(bytes[0] === 31 && bytes[1] === 139),
196060
+ raw: !wrapped,
196059
196061
  chunkSize: Math.max(1, Math.min(64 * 1024, maxDecodedBytes + 1))
196060
196062
  });
196063
+ const chunks = [];
196061
196064
  let length = 0;
196062
196065
  decoder2.onData = (chunk) => {
196063
196066
  length += chunk.length;
196064
196067
  if (length > maxDecodedBytes) {
196065
196068
  throw new PdfError2("E_LIMIT", "FlateDecode output exceeds maximum decoded byte budget");
196066
196069
  }
196067
- decoder2.chunks.push(chunk);
196070
+ chunks.push(chunk);
196068
196071
  };
196069
- if (!decoder2.push(bytes, true) || decoder2.err || !decoder2.ended) {
196072
+ const complete2 = decoder2.push(bytes, true);
196073
+ const truncated = wrapped && decoder2.err === Z_BUF_ERROR2 && length > 0;
196074
+ if ((!complete2 || decoder2.err || !decoder2.ended) && !truncated) {
196070
196075
  throw new PdfError2("E_CAPABILITY", "Invalid FlateDecode compressed stream");
196071
196076
  }
196072
- inflated = decoder2.result;
196077
+ inflated = new Uint8Array(length);
196078
+ let offset = 0;
196079
+ for (const chunk of chunks) {
196080
+ inflated.set(chunk, offset);
196081
+ offset += chunk.length;
196082
+ }
196073
196083
  }
196074
196084
  return applyPredictor(inflated, parms);
196075
196085
  }
@@ -207958,7 +207968,7 @@ function resolvePageFonts(doc, resourcesDict) {
207958
207968
  const glyphNames = buildFontEncodingGlyphNamesMap(encNode);
207959
207969
  const widths = /* @__PURE__ */ new Map();
207960
207970
  let defaultWidth = 556;
207961
- const isTwoByteCid = subtype === "Type0" || Boolean(cmap?.isTwoByte);
207971
+ const isTwoByteCid = subtype === "Type0";
207962
207972
  let fontMatrix;
207963
207973
  let charProcs;
207964
207974
  let fontResources;
@@ -209411,7 +209421,7 @@ function evaluateContentStreamToDisplayList(params) {
209411
209421
  const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
209412
209422
  transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
209413
209423
  } else if (seg.kind === "rect") {
209414
- if (hasRotOrShear) {
209424
+ if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
209415
209425
  const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
209416
209426
  const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
209417
209427
  const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
@@ -209444,7 +209454,12 @@ function evaluateContentStreamToDisplayList(params) {
209444
209454
  transformedSegments.push({ kind: "close" });
209445
209455
  }
209446
209456
  }
209447
- if (node3.clip && transformedSegments.length > 0) {
209457
+ const applyClip = () => {
209458
+ if (!node3.clip) return;
209459
+ st.clipPaths = [...st.clipPaths ?? [], {
209460
+ segments: transformedSegments,
209461
+ fillRule: node3.clip === "W*" ? "evenodd" : "nonzero"
209462
+ }];
209448
209463
  let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
209449
209464
  for (const s of transformedSegments) {
209450
209465
  if (s.kind === "move" || s.kind === "line") {
@@ -209472,8 +209487,11 @@ function evaluateContentStreamToDisplayList(params) {
209472
209487
  Math.min(st.clipRect[3], cMaxY)
209473
209488
  ] : [cMinX, cMinY, cMaxX, cMaxY];
209474
209489
  }
209490
+ };
209491
+ if (node3.paint === "n") {
209492
+ applyClip();
209493
+ break;
209475
209494
  }
209476
- if (node3.paint === "n") break;
209477
209495
  const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node3.paint);
209478
209496
  const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node3.paint);
209479
209497
  let evaluatedFillPattern = false;
@@ -209606,7 +209624,10 @@ function evaluateContentStreamToDisplayList(params) {
209606
209624
  }
209607
209625
  }
209608
209626
  }
209609
- if (evaluatedFillPattern && !isStroke) break;
209627
+ if (evaluatedFillPattern && !isStroke) {
209628
+ applyClip();
209629
+ break;
209630
+ }
209610
209631
  const fillRule = node3.paint.includes("*") ? "evenodd" : "nonzero";
209611
209632
  const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
209612
209633
  const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
@@ -209626,6 +209647,7 @@ function evaluateContentStreamToDisplayList(params) {
209626
209647
  ...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
209627
209648
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
209628
209649
  } });
209650
+ applyClip();
209629
209651
  break;
209630
209652
  }
209631
209653
  case "xobject": {
@@ -212949,8 +212971,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale2, closeSubpaths = fal
212949
212971
  if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
212950
212972
  edges2.push({ x0: curX, y0: curY, x1: startX, y1: startY });
212951
212973
  }
212952
- const [rx0, ry0] = toScreen(seg.x, seg.y + seg.height);
212953
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
212974
+ const [rx0, ry0] = toScreen(seg.x, seg.y);
212975
+ const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
212954
212976
  edges2.push(
212955
212977
  { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
212956
212978
  { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
@@ -213093,21 +213115,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213093
213115
  }
213094
213116
  const aaVec = options.antialiasVector !== false;
213095
213117
  const aaTxt = options.antialiasText !== false;
213096
- const clipMasks = /* @__PURE__ */ new Map();
213118
+ let cachedClips;
213119
+ let cachedClipMask;
213097
213120
  const imageClipMasks = /* @__PURE__ */ new Map();
213098
213121
  for (const original of paintOperations(displayList)) {
213099
213122
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
213100
213123
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
213101
213124
  const clips = original.value.clipPaths;
213102
- let clipMask = clips ? clipMasks.get(clips) : void 0;
213125
+ let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
213103
213126
  if (clips && !clipMask) {
213104
213127
  clipMask = new Uint8Array(width2 * height * 4).fill(255);
213105
- for (const segments of clips) {
213128
+ for (const clip2 of clips) {
213129
+ const { segments, fillRule } = "segments" in clip2 ? clip2 : { segments: clip2, fillRule: "nonzero" };
213106
213130
  const layer = new Uint8Array(width2 * height * 4);
213107
- fillEdgesScanline4x4(layer, width2, height, segmentsToScreenEdges(segments, displayList.height, scale2, true), { r: 1, g: 1, b: 1 });
213131
+ fillEdgesScanline4x4(layer, width2, height, segmentsToScreenEdges(segments, displayList.height, scale2, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
213108
213132
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
213109
213133
  }
213110
- clipMasks.set(clips, clipMask);
213134
+ cachedClips = clips;
213135
+ cachedClipMask = clipMask;
213111
213136
  }
213112
213137
  const imageClips = original.value.clipImages;
213113
213138
  if (imageClips) {
@@ -2604,22 +2604,31 @@ function decodeFlate(bytes, parms, maxDecodedBytes = DEFAULT_MAX_DECODED_BYTES)
2604
2604
  inflated = new BoundedFlateStream(bytes, maxDecodedBytes).getBytes();
2605
2605
  } catch (error) {
2606
2606
  if (error instanceof PdfError && error.code === "E_LIMIT") throw error;
2607
+ const wrapped = bytes[0] === 31 && bytes[1] === 139 || bytes.length >= 2 && (bytes[0] & 15) === 8 && bytes[0] >>> 4 <= 7 && (bytes[0] << 8 | bytes[1]) % 31 === 0;
2607
2608
  const decoder2 = new Inflate({
2608
- raw: !(bytes[0] === 31 && bytes[1] === 139),
2609
+ raw: !wrapped,
2609
2610
  chunkSize: Math.max(1, Math.min(64 * 1024, maxDecodedBytes + 1))
2610
2611
  });
2612
+ const chunks = [];
2611
2613
  let length2 = 0;
2612
2614
  decoder2.onData = (chunk) => {
2613
2615
  length2 += chunk.length;
2614
2616
  if (length2 > maxDecodedBytes) {
2615
2617
  throw new PdfError("E_LIMIT", "FlateDecode output exceeds maximum decoded byte budget");
2616
2618
  }
2617
- decoder2.chunks.push(chunk);
2619
+ chunks.push(chunk);
2618
2620
  };
2619
- if (!decoder2.push(bytes, true) || decoder2.err || !decoder2.ended) {
2621
+ const complete = decoder2.push(bytes, true);
2622
+ const truncated = wrapped && decoder2.err === Z_BUF_ERROR && length2 > 0;
2623
+ if ((!complete || decoder2.err || !decoder2.ended) && !truncated) {
2620
2624
  throw new PdfError("E_CAPABILITY", "Invalid FlateDecode compressed stream");
2621
2625
  }
2622
- inflated = decoder2.result;
2626
+ inflated = new Uint8Array(length2);
2627
+ let offset = 0;
2628
+ for (const chunk of chunks) {
2629
+ inflated.set(chunk, offset);
2630
+ offset += chunk.length;
2631
+ }
2623
2632
  }
2624
2633
  return applyPredictor(inflated, parms);
2625
2634
  }
@@ -10490,7 +10499,7 @@ function resolvePageFonts(doc, resourcesDict) {
10490
10499
  const glyphNames = buildFontEncodingGlyphNamesMap(encNode);
10491
10500
  const widths = /* @__PURE__ */ new Map();
10492
10501
  let defaultWidth = 556;
10493
- const isTwoByteCid = subtype === "Type0" || Boolean(cmap?.isTwoByte);
10502
+ const isTwoByteCid = subtype === "Type0";
10494
10503
  let fontMatrix;
10495
10504
  let charProcs;
10496
10505
  let fontResources;
@@ -11943,7 +11952,7 @@ function evaluateContentStreamToDisplayList(params) {
11943
11952
  const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
11944
11953
  transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
11945
11954
  } else if (seg.kind === "rect") {
11946
- if (hasRotOrShear) {
11955
+ if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
11947
11956
  const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
11948
11957
  const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
11949
11958
  const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
@@ -11976,7 +11985,12 @@ function evaluateContentStreamToDisplayList(params) {
11976
11985
  transformedSegments.push({ kind: "close" });
11977
11986
  }
11978
11987
  }
11979
- if (node.clip && transformedSegments.length > 0) {
11988
+ const applyClip = () => {
11989
+ if (!node.clip) return;
11990
+ st.clipPaths = [...st.clipPaths ?? [], {
11991
+ segments: transformedSegments,
11992
+ fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
11993
+ }];
11980
11994
  let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
11981
11995
  for (const s of transformedSegments) {
11982
11996
  if (s.kind === "move" || s.kind === "line") {
@@ -12004,8 +12018,11 @@ function evaluateContentStreamToDisplayList(params) {
12004
12018
  Math.min(st.clipRect[3], cMaxY)
12005
12019
  ] : [cMinX, cMinY, cMaxX, cMaxY];
12006
12020
  }
12021
+ };
12022
+ if (node.paint === "n") {
12023
+ applyClip();
12024
+ break;
12007
12025
  }
12008
- if (node.paint === "n") break;
12009
12026
  const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
12010
12027
  const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
12011
12028
  let evaluatedFillPattern = false;
@@ -12138,7 +12155,10 @@ function evaluateContentStreamToDisplayList(params) {
12138
12155
  }
12139
12156
  }
12140
12157
  }
12141
- if (evaluatedFillPattern && !isStroke) break;
12158
+ if (evaluatedFillPattern && !isStroke) {
12159
+ applyClip();
12160
+ break;
12161
+ }
12142
12162
  const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
12143
12163
  const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
12144
12164
  const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
@@ -12158,6 +12178,7 @@ function evaluateContentStreamToDisplayList(params) {
12158
12178
  ...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
12159
12179
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
12160
12180
  } });
12181
+ applyClip();
12161
12182
  break;
12162
12183
  }
12163
12184
  case "xobject": {
@@ -14384,8 +14405,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
14384
14405
  if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
14385
14406
  edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
14386
14407
  }
14387
- const [rx0, ry0] = toScreen(seg.x, seg.y + seg.height);
14388
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
14408
+ const [rx0, ry0] = toScreen(seg.x, seg.y);
14409
+ const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
14389
14410
  edges.push(
14390
14411
  { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
14391
14412
  { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
@@ -14528,21 +14549,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
14528
14549
  }
14529
14550
  const aaVec = options.antialiasVector !== false;
14530
14551
  const aaTxt = options.antialiasText !== false;
14531
- const clipMasks = /* @__PURE__ */ new Map();
14552
+ let cachedClips;
14553
+ let cachedClipMask;
14532
14554
  const imageClipMasks = /* @__PURE__ */ new Map();
14533
14555
  for (const original of paintOperations(displayList)) {
14534
14556
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
14535
14557
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
14536
14558
  const clips = original.value.clipPaths;
14537
- let clipMask = clips ? clipMasks.get(clips) : void 0;
14559
+ let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
14538
14560
  if (clips && !clipMask) {
14539
14561
  clipMask = new Uint8Array(width * height * 4).fill(255);
14540
- for (const segments of clips) {
14562
+ for (const clip of clips) {
14563
+ const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
14541
14564
  const layer = new Uint8Array(width * height * 4);
14542
- fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
14565
+ fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
14543
14566
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
14544
14567
  }
14545
- clipMasks.set(clips, clipMask);
14568
+ cachedClips = clips;
14569
+ cachedClipMask = clipMask;
14546
14570
  }
14547
14571
  const imageClips = original.value.clipImages;
14548
14572
  if (imageClips) {
@@ -14927,6 +14951,7 @@ var makeTable;
14927
14951
  var crcTable;
14928
14952
  var crc32;
14929
14953
  var messages_default;
14954
+ var Z_BUF_ERROR;
14930
14955
  var MAX_MEM_LEVEL;
14931
14956
  var HEAP_SIZE;
14932
14957
  var MIN_MATCH;
@@ -15929,6 +15954,7 @@ var init_dist = __esm({
15929
15954
  "-5": "buffer error",
15930
15955
  "-6": "incompatible version"
15931
15956
  };
15957
+ Z_BUF_ERROR = -5;
15932
15958
  MAX_MEM_LEVEL = 9;
15933
15959
  HEAP_SIZE = 573;
15934
15960
  MIN_MATCH = 3;
@@ -1,8 +1,8 @@
1
1
  import { type ByteSource, type CommandContext, type CommandDefinition, type CommandHandler, type CommandResult } from "../safe-bash-contracts/index.js";
2
2
  export declare const RESOLVED_EXIT_ZERO: Promise<CommandResult>;
3
3
  export declare const RESOLVED_EXIT_ONE: Promise<CommandResult>;
4
- export declare const encoder: TextEncoder;
5
- export declare const decoder: TextDecoder;
4
+ export declare const encoder: InstanceType<typeof TextEncoder>;
5
+ export declare const decoder: InstanceType<typeof TextDecoder>;
6
6
  export declare const bufferLimit: number;
7
7
  export { builtInDirectContextExecutors } from "../safe-bash-contracts/runtime-control.js";
8
8
  export { isDefaultCommandOptions, registerDefaultExecutor, registerDefaultExecutors } from "../safe-bash-contracts/command.js";