@poe-platform/safe-bash 0.1.779 → 0.1.781

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 (112) hide show
  1. package/dist/image-ast/index.browser.js +200 -165
  2. package/dist/image-ast/index.js +200 -165
  3. package/dist/pdf-ast/index.js +200 -165
  4. package/dist/safe-bash/command-chunks/{chunk-ELX7X5SF.js → chunk-2MPJNOGU.js} +3 -3
  5. package/dist/safe-bash/command-chunks/{chunk-NT6N3KCA.js → chunk-36A7T7VI.js} +1 -1
  6. package/dist/safe-bash/command-chunks/{chunk-W7K4JN2M.js → chunk-3AQJQW6S.js} +1 -1
  7. package/dist/safe-bash/command-chunks/{chunk-T6ZPGCNJ.js → chunk-3DVCCMBJ.js} +2 -1
  8. package/dist/safe-bash/command-chunks/{chunk-XQZ3OG7K.js → chunk-442UWLQR.js} +1 -1
  9. package/dist/safe-bash/command-chunks/{chunk-W6UOCPP2.js → chunk-7THHNO2E.js} +1 -1
  10. package/dist/safe-bash/command-chunks/{chunk-ZY6PMCW5.js → chunk-ADBFNLLK.js} +2 -2
  11. package/dist/safe-bash/command-chunks/{chunk-ZMCVEYVX.js → chunk-AXO7RDN5.js} +1 -1
  12. package/dist/safe-bash/command-chunks/{chunk-PLOA5HZJ.js → chunk-BHOK6HA3.js} +4 -4
  13. package/dist/safe-bash/command-chunks/{chunk-TEVDQ3XP.js → chunk-C2JGBXOY.js} +2 -2
  14. package/dist/safe-bash/command-chunks/{chunk-MANR67FK.js → chunk-CD2SMRKD.js} +4 -4
  15. package/dist/safe-bash/command-chunks/{chunk-IFMCWC7A.js → chunk-CXDWDFFU.js} +2 -2
  16. package/dist/safe-bash/command-chunks/{chunk-TETIL2QG.js → chunk-FDJBYW3P.js} +1 -1
  17. package/dist/safe-bash/command-chunks/{chunk-OTTXGYBL.js → chunk-G3O44ZGT.js} +2 -2
  18. package/dist/safe-bash/command-chunks/{chunk-TUX2ZVRV.js → chunk-G5XIFXNF.js} +1 -1
  19. package/dist/safe-bash/command-chunks/{chunk-QLYJUVVM.js → chunk-GBHSE6ZO.js} +1 -1
  20. package/dist/safe-bash/command-chunks/{chunk-3PBP2NWM.js → chunk-GEHF4YAY.js} +1 -1
  21. package/dist/safe-bash/command-chunks/{chunk-3444RZLY.js → chunk-GZXLPWT5.js} +200 -165
  22. package/dist/safe-bash/command-chunks/{chunk-B7CSA2AN.js → chunk-KEMWQP25.js} +1 -1
  23. package/dist/safe-bash/command-chunks/{chunk-VGKASRY7.js → chunk-KI2XV6GF.js} +1 -1
  24. package/dist/safe-bash/command-chunks/{chunk-T4BURXBK.js → chunk-KL4ODNMV.js} +3 -3
  25. package/dist/safe-bash/command-chunks/{chunk-YRMCH7OE.js → chunk-LCR6YMBL.js} +1 -1
  26. package/dist/safe-bash/command-chunks/{chunk-YUBBOIPH.js → chunk-LP5NRR5O.js} +1 -1
  27. package/dist/safe-bash/command-chunks/{chunk-4SZIRINP.js → chunk-OEPERWLZ.js} +2 -1
  28. package/dist/safe-bash/command-chunks/{chunk-QYSAAJ6K.js → chunk-PUIGJ37F.js} +1 -1
  29. package/dist/safe-bash/command-chunks/{chunk-O4ARSYST.js → chunk-QSD4I3TT.js} +4 -3
  30. package/dist/safe-bash/command-chunks/{chunk-KDVJQQVT.js → chunk-QTKPEWR7.js} +4 -4
  31. package/dist/safe-bash/command-chunks/{chunk-EYRJX6FJ.js → chunk-TICYYKJB.js} +2 -1
  32. package/dist/safe-bash/command-chunks/{chunk-TKBJACLG.js → chunk-VXDCTI33.js} +1 -1
  33. package/dist/safe-bash/command-chunks/{chunk-MAZIL3QC.js → chunk-WQHCF6N6.js} +1 -1
  34. package/dist/safe-bash/command-chunks/{chunk-I7PJVVOO.js → chunk-XFQAGBAV.js} +1 -1
  35. package/dist/safe-bash/command-chunks/{chunk-DYCEVLVC.js → chunk-Y6YHBQIS.js} +1 -1
  36. package/dist/safe-bash/command-chunks/{chunk-OPRPIHKA.js → chunk-ZGBHQQGL.js} +1 -1
  37. package/dist/safe-bash/command-chunks/{chunk-6QG3YR2F.js → chunk-ZPQ5OCKE.js} +1 -1
  38. package/dist/safe-bash/commands/diff-patch/shared.d.ts +1 -0
  39. package/dist/safe-bash/commands/diff-patch/shared.js +2 -1
  40. package/dist/safe-bash/core.browser.js +2 -1
  41. package/dist/safe-bash/opt-in/commands/dd/index.js +2 -1
  42. package/dist/safe-bash/opt-in/commands/shuf/input.js +4 -2
  43. package/dist/safe-bash/opt-in/commands/shuf/shuf.js +4 -3
  44. package/dist/safe-bash-command-dd/index.js +2 -1
  45. package/dist/safe-bash-command-du/budget.js +1 -1
  46. package/dist/safe-bash-command-du/du.js +2 -2
  47. package/dist/safe-bash-command-du/index.js +2 -2
  48. package/dist/safe-bash-command-ffmpeg/index.js +5745 -5715
  49. package/dist/safe-bash-command-file/index.js +1 -1
  50. package/dist/safe-bash-command-file/shared.d.ts +1 -0
  51. package/dist/safe-bash-command-file/shared.js +1 -1
  52. package/dist/safe-bash-command-fmt/index.js +2 -1
  53. package/dist/safe-bash-command-html-to-markdown/budget.js +1 -1
  54. package/dist/safe-bash-command-html-to-markdown/entities.js +3 -3
  55. package/dist/safe-bash-command-html-to-markdown/index.js +6 -6
  56. package/dist/safe-bash-command-html-to-markdown/input.js +5 -5
  57. package/dist/safe-bash-command-html-to-markdown/parser.js +4 -4
  58. package/dist/safe-bash-command-html-to-markdown/render.js +5 -5
  59. package/dist/safe-bash-command-html-to-markdown/text.js +2 -2
  60. package/dist/safe-bash-command-iconv/command.js +5 -5
  61. package/dist/safe-bash-command-iconv/index.js +5 -5
  62. package/dist/safe-bash-command-iconv/internal.js +1 -1
  63. package/dist/safe-bash-command-iconv/lifecycle.js +2 -2
  64. package/dist/safe-bash-command-iconv/options.js +2 -2
  65. package/dist/safe-bash-command-iconv/reader.js +2 -2
  66. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  67. package/dist/safe-bash-command-numfmt/index.js +5 -3
  68. package/dist/safe-bash-command-pandoc/command.js +3 -3
  69. package/dist/safe-bash-command-pandoc/index.js +3 -3
  70. package/dist/safe-bash-command-pdfimages/index.js +200 -165
  71. package/dist/safe-bash-command-pdfinfo/index.js +200 -165
  72. package/dist/safe-bash-command-pdftk/index.js +200 -165
  73. package/dist/safe-bash-command-pdftoppm/index.js +200 -165
  74. package/dist/safe-bash-command-pdftotext/index.js +200 -165
  75. package/dist/safe-bash-command-pr/command.js +5 -5
  76. package/dist/safe-bash-command-pr/format.js +2 -2
  77. package/dist/safe-bash-command-pr/index.js +5 -5
  78. package/dist/safe-bash-command-pr/internal.d.ts +1 -0
  79. package/dist/safe-bash-command-pr/internal.js +1 -1
  80. package/dist/safe-bash-command-pr/io.js +2 -2
  81. package/dist/safe-bash-command-pr/options.js +2 -2
  82. package/dist/safe-bash-command-qpdf/index.js +200 -165
  83. package/dist/safe-bash-command-shuf/input.js +4 -2
  84. package/dist/safe-bash-command-shuf/shuf.js +4 -3
  85. package/dist/safe-bash-command-sips/index.js +2 -2
  86. package/dist/safe-bash-command-soffice/index.js +1 -1
  87. package/dist/safe-bash-command-split/index.js +3 -3
  88. package/dist/safe-bash-command-split/io.d.ts +1 -0
  89. package/dist/safe-bash-command-split/io.js +1 -1
  90. package/dist/safe-bash-command-split/outputs.js +2 -2
  91. package/dist/safe-bash-command-split/split.js +3 -3
  92. package/dist/safe-bash-command-ssconvert/index.js +200 -165
  93. package/dist/safe-bash-command-tree/arguments.js +3 -3
  94. package/dist/safe-bash-command-tree/charset.js +1 -1
  95. package/dist/safe-bash-command-tree/index.js +4 -4
  96. package/dist/safe-bash-command-tree/io.js +1 -1
  97. package/dist/safe-bash-command-tree/pattern.js +2 -2
  98. package/dist/safe-bash-command-tree/tree.js +4 -4
  99. package/dist/safe-bash-command-tsort/command.js +4 -4
  100. package/dist/safe-bash-command-tsort/graph.js +2 -2
  101. package/dist/safe-bash-command-tsort/index.js +4 -4
  102. package/dist/safe-bash-command-tsort/internal.js +1 -1
  103. package/dist/safe-bash-command-tsort/io.js +2 -2
  104. package/dist/safe-bash-command-wkhtmltopdf/index.js +201 -165
  105. package/dist/safe-bash-io-engine/commands/archive/internal.js +2 -2
  106. package/dist/safe-bash-io-engine/shell/pattern.js +1 -1
  107. package/dist/safe-bash-io-engine/shell/string-operations.d.ts +1 -0
  108. package/dist/safe-bash-io-engine/shell/string-operations.js +1 -1
  109. package/dist/safe-bash-text-stream-engine/stream-format/shared.d.ts +1 -0
  110. package/dist/safe-bash-text-stream-engine/stream-format/shared.js +2 -1
  111. package/package.json +2 -2
  112. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +73 -5
@@ -34564,7 +34564,7 @@ function cosString(value, span) {
34564
34564
  if (typeof value === "string") {
34565
34565
  let needsUtf16 = false;
34566
34566
  for (let i = 0; i < value.length; i++) {
34567
- if (value.charCodeAt(i) > 255) {
34567
+ if (!PDF_DOC_ENCODING_REVERSE.has(value.charCodeAt(i))) {
34568
34568
  needsUtf16 = true;
34569
34569
  break;
34570
34570
  }
@@ -34582,7 +34582,7 @@ function cosString(value, span) {
34582
34582
  }
34583
34583
  const bytes = new Uint8Array(value.length);
34584
34584
  for (let i = 0; i < value.length; i++) {
34585
- bytes[i] = value.charCodeAt(i) & 255;
34585
+ bytes[i] = PDF_DOC_ENCODING_REVERSE.get(value.charCodeAt(i));
34586
34586
  }
34587
34587
  return { kind: "string", format: "literal", bytes, span };
34588
34588
  }
@@ -34729,6 +34729,9 @@ var PDF_DOC_ENCODING_MAP = {
34729
34729
  160: 8364,
34730
34730
  173: 65533
34731
34731
  };
34732
+ var PDF_DOC_ENCODING_REVERSE = new Map(
34733
+ Array.from({ length: 256 }, (_, byte) => [PDF_DOC_ENCODING_MAP[byte] ?? byte, byte])
34734
+ );
34732
34735
  function decodeUtf16UnitsWithSurrogateCheck(units) {
34733
34736
  let out = "";
34734
34737
  for (let i = 0; i < units.length; i++) {
@@ -35020,6 +35023,7 @@ var CosByteLexer = class {
35020
35023
  const start = this.pos;
35021
35024
  this.pos++;
35022
35025
  let depth = 1;
35026
+ let recovery;
35023
35027
  const out = [];
35024
35028
  while (this.pos < this.end && depth > 0) {
35025
35029
  const b = this.bytes[this.pos++];
@@ -35054,7 +35058,15 @@ var CosByteLexer = class {
35054
35058
  out.push(b);
35055
35059
  } else if (b === 41) {
35056
35060
  depth--;
35057
- if (depth > 0) out.push(b);
35061
+ if (depth > 0) {
35062
+ const next = this.bytes[this.pos];
35063
+ const afterLine = next === 13 && this.bytes[this.pos + 1] === 10 ? this.pos + 2 : this.pos + 1;
35064
+ const delimiter = this.bytes[afterLine];
35065
+ if (!recovery && this.pos + 2 < this.end && (next === 10 || next === 13) && (delimiter === 47 || delimiter === 62)) {
35066
+ recovery = { offset: this.pos, length: out.length };
35067
+ }
35068
+ out.push(b);
35069
+ }
35058
35070
  } else if (b === 13) {
35059
35071
  if (this.pos < this.end && this.bytes[this.pos] === 10) this.pos++;
35060
35072
  out.push(10);
@@ -35065,6 +35077,10 @@ var CosByteLexer = class {
35065
35077
  throw new PdfError("E_LIMIT", "PDF literal string exceeds maximum byte length");
35066
35078
  }
35067
35079
  }
35080
+ if (depth > 0 && recovery) {
35081
+ this.pos = recovery.offset;
35082
+ out.length = recovery.length;
35083
+ }
35068
35084
  return {
35069
35085
  kind: "string",
35070
35086
  bytes: Uint8Array.from(out),
@@ -46436,6 +46452,7 @@ function evaluateContentStreamToDisplayList(params) {
46436
46452
  };
46437
46453
  const initialState = {
46438
46454
  ctm: [1, 0, 0, 1, 0, 0],
46455
+ initialCtm: [1, 0, 0, 1, 0, 0],
46439
46456
  strokeColor: { r: 0, g: 0, b: 0 },
46440
46457
  fillColor: { r: 0, g: 0, b: 0 },
46441
46458
  strokeAlpha: 1,
@@ -46733,6 +46750,116 @@ function evaluateContentStreamToDisplayList(params) {
46733
46750
  ] }], void 0, void 0, resources, activeFonts, depth);
46734
46751
  stateStack.pop();
46735
46752
  };
46753
+ const paintPattern = (segments, fillRule, resources, activeFonts, depth, mcid, actualText) => {
46754
+ const st = curState(), doc = params.cosDoc;
46755
+ if (!st.fillPatternName || !doc || !resources) return false;
46756
+ if (depth >= 8) throw new PdfError("E_LIMIT", "Pattern nesting exceeds the form depth limit");
46757
+ const patterns = doc.resolveDict(dictGet(resources, "Pattern"));
46758
+ const pattern = patterns && doc.resolve(dictGet(patterns, st.fillPatternName));
46759
+ const dict = pattern?.kind === "stream" ? pattern.dict : pattern?.kind === "dict" ? pattern : void 0;
46760
+ if (!dict) return false;
46761
+ const nums = (key, fallback) => {
46762
+ const array = doc.resolveArray(dictGet(dict, key));
46763
+ return array ? array.items.map((item, i) => {
46764
+ const value = doc.resolve(item);
46765
+ return value?.kind === "number" ? value.value : fallback[i] ?? 0;
46766
+ }) : fallback;
46767
+ };
46768
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
46769
+ const include = (x, y) => {
46770
+ x0 = Math.min(x0, x);
46771
+ y0 = Math.min(y0, y);
46772
+ x1 = Math.max(x1, x);
46773
+ y1 = Math.max(y1, y);
46774
+ };
46775
+ for (const segment of segments) {
46776
+ if (segment.kind === "close") continue;
46777
+ include(segment.x, segment.y);
46778
+ if (segment.kind === "cubic") {
46779
+ include(segment.x1, segment.y1);
46780
+ include(segment.x2, segment.y2);
46781
+ }
46782
+ if (segment.kind === "rect") include(segment.x + segment.width, segment.y + segment.height);
46783
+ }
46784
+ const [originX, originY] = params.origin ?? [0, 0];
46785
+ const clip = st.clipRect ?? [originX, originY, originX + params.width, originY + params.height];
46786
+ const bounds = [Math.max(x0, clip[0]), Math.max(y0, clip[1]), Math.min(x1, clip[2]), Math.min(y1, clip[3])];
46787
+ if (!(bounds[2] > bounds[0] && bounds[3] > bounds[1])) return true;
46788
+ const matrix = multiplyMatrices(nums("Matrix", [1, 0, 0, 1, 0, 0]), st.initialCtm);
46789
+ const type = doc.resolve(dictGet(dict, "PatternType"));
46790
+ stateStack.push({ ...st, clipRect: bounds, clipPaths: [...st.clipPaths ?? [], { segments, fillRule }] });
46791
+ try {
46792
+ if (type?.kind === "number" && type.value === 2) {
46793
+ const shading = doc.resolve(dictGet(dict, "Shading"));
46794
+ const shadingDict = shading?.kind === "stream" ? shading.dict : shading?.kind === "dict" ? shading : void 0;
46795
+ if (!shadingDict) return false;
46796
+ const image = renderShadingDictToImage(
46797
+ doc,
46798
+ shadingDict,
46799
+ matrix,
46800
+ bounds,
46801
+ st.fillAlpha,
46802
+ "PatternShading_" + st.fillPatternName,
46803
+ bounds,
46804
+ shading?.kind === "stream" ? shading : void 0,
46805
+ st.blendMode
46806
+ );
46807
+ if (image) emit({ kind: "image", value: image });
46808
+ return !!image;
46809
+ }
46810
+ if (pattern?.kind !== "stream") return false;
46811
+ const xStepNode = doc.resolve(dictGet(dict, "XStep"));
46812
+ const yStepNode = doc.resolve(dictGet(dict, "YStep"));
46813
+ const xStep = xStepNode?.kind === "number" ? Math.abs(xStepNode.value) : 0;
46814
+ const yStep = yStepNode?.kind === "number" ? Math.abs(yStepNode.value) : 0;
46815
+ const determinant = matrix[0] * matrix[3] - matrix[1] * matrix[2];
46816
+ if (!xStep || !yStep || !determinant) return true;
46817
+ const inverse = [
46818
+ matrix[3] / determinant,
46819
+ -matrix[1] / determinant,
46820
+ -matrix[2] / determinant,
46821
+ matrix[0] / determinant,
46822
+ (matrix[2] * matrix[5] - matrix[3] * matrix[4]) / determinant,
46823
+ (matrix[1] * matrix[4] - matrix[0] * matrix[5]) / determinant
46824
+ ];
46825
+ const corners = [[bounds[0], bounds[1]], [bounds[2], bounds[1]], [bounds[2], bounds[3]], [bounds[0], bounds[3]]].map(([x, y]) => transformPoint(inverse, x, y));
46826
+ const box = nums("BBox", [0, 0, xStep, yStep]);
46827
+ const ix0 = Math.floor((Math.min(...corners.map((p) => p[0])) - box[2]) / xStep) + 1;
46828
+ const ix1 = Math.ceil((Math.max(...corners.map((p) => p[0])) - box[0]) / xStep) - 1;
46829
+ const iy0 = Math.floor((Math.min(...corners.map((p) => p[1])) - box[3]) / yStep) + 1;
46830
+ const iy1 = Math.ceil((Math.max(...corners.map((p) => p[1])) - box[1]) / yStep) - 1;
46831
+ if ((ix1 - ix0 + 1) * (iy1 - iy0 + 1) > 2e4) throw new PdfError("E_LIMIT", "Pattern tile count exceeds 20000");
46832
+ const nodes = parseContentStream(doc.decodeStream(pattern));
46833
+ const patternResources = doc.resolveDict(dictGet(dict, "Resources")) ?? resources;
46834
+ const patternFonts = new Map(activeFonts);
46835
+ for (const [key, font] of resolvePageFonts(doc, patternResources)) patternFonts.set(key, font);
46836
+ for (let iy = iy0; iy <= iy1; iy++) {
46837
+ for (let ix = ix0; ix <= ix1; ix++) {
46838
+ const tileCtm = multiplyMatrices([1, 0, 0, 1, ix * xStep, iy * yStep], matrix);
46839
+ const points = [[box[0], box[1]], [box[2], box[1]], [box[2], box[3]], [box[0], box[3]]].map(([x, y]) => transformPoint(tileCtm, x, y));
46840
+ const tileClip = [
46841
+ ...points.map(([x, y], i) => ({ kind: i === 0 ? "move" : "line", x, y })),
46842
+ { kind: "close" }
46843
+ ];
46844
+ stateStack.push({
46845
+ ...curState(),
46846
+ fillPatternName: void 0,
46847
+ ctm: tileCtm,
46848
+ initialCtm: tileCtm,
46849
+ clipPaths: [...curState().clipPaths ?? [], tileClip]
46850
+ });
46851
+ try {
46852
+ walkNodes(nodes, mcid, actualText, patternResources, patternFonts, depth + 1);
46853
+ } finally {
46854
+ stateStack.pop();
46855
+ }
46856
+ }
46857
+ }
46858
+ return true;
46859
+ } finally {
46860
+ stateStack.pop();
46861
+ }
46862
+ };
46736
46863
  const paintForm = (form, activeResources, activeFonts, depth, mcid, actualText, maskGroup = false) => {
46737
46864
  const st = curState();
46738
46865
  const group = params.cosDoc.resolveDict(dictGet(form.dict, "Group"));
@@ -46791,7 +46918,7 @@ function evaluateContentStreamToDisplayList(params) {
46791
46918
  }
46792
46919
  const parentOperations = capturedOperations;
46793
46920
  const children = [];
46794
- const nextState = { ...st, ctm: nextCtm };
46921
+ const nextState = { ...st, ctm: nextCtm, initialCtm: nextCtm };
46795
46922
  if (compositeGroup) {
46796
46923
  capturedOperations = children;
46797
46924
  nextState.fillAlpha = nextState.strokeAlpha = 1;
@@ -46949,136 +47076,15 @@ function evaluateContentStreamToDisplayList(params) {
46949
47076
  }
46950
47077
  const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
46951
47078
  const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
46952
- let evaluatedFillPattern = false;
46953
- if (isFill && st.fillPatternName && params.cosDoc && activeResources && depth < 6) {
46954
- const patMap = params.cosDoc.resolveDict(dictGet(activeResources, "Pattern"));
46955
- const patNode = patMap ? params.cosDoc.resolve(dictGet(patMap, st.fillPatternName)) : void 0;
46956
- const patDict = patNode?.kind === "stream" ? patNode.dict : patNode?.kind === "dict" ? patNode : void 0;
46957
- const patTypeNode = patDict && params.cosDoc ? params.cosDoc.resolve(dictGet(patDict, "PatternType")) : void 0;
46958
- const patType = patTypeNode?.kind === "number" ? patTypeNode.value : patNode?.kind === "stream" ? 1 : 0;
46959
- if (patDict && patType === 2 && params.cosDoc) {
46960
- let pMinX = Infinity, pMinY = Infinity, pMaxX = -Infinity, pMaxY = -Infinity;
46961
- for (const s of transformedSegments) {
46962
- if (s.kind === "move" || s.kind === "line") {
46963
- pMinX = Math.min(pMinX, s.x);
46964
- pMinY = Math.min(pMinY, s.y);
46965
- pMaxX = Math.max(pMaxX, s.x);
46966
- pMaxY = Math.max(pMaxY, s.y);
46967
- } else if (s.kind === "cubic") {
46968
- pMinX = Math.min(pMinX, s.x1, s.x2, s.x);
46969
- pMinY = Math.min(pMinY, s.y1, s.y2, s.y);
46970
- pMaxX = Math.max(pMaxX, s.x1, s.x2, s.x);
46971
- pMaxY = Math.max(pMaxY, s.y1, s.y2, s.y);
46972
- } else if (s.kind === "rect") {
46973
- pMinX = Math.min(pMinX, s.x);
46974
- pMinY = Math.min(pMinY, s.y);
46975
- pMaxX = Math.max(pMaxX, s.x + s.width);
46976
- pMaxY = Math.max(pMaxY, s.y + s.height);
46977
- }
46978
- }
46979
- if (Number.isFinite(pMinX) && Number.isFinite(pMinY) && pMaxX > pMinX && pMaxY > pMinY) {
46980
- const shading = params.cosDoc.resolve(dictGet(patDict, "Shading"));
46981
- const shDict = shading?.kind === "stream" ? shading.dict : shading?.kind === "dict" ? shading : void 0;
46982
- if (shDict) {
46983
- let patMatrix = [1, 0, 0, 1, 0, 0];
46984
- const pmArr = params.cosDoc.resolveArray(dictGet(patDict, "Matrix"));
46985
- if (pmArr && pmArr.items.length >= 6) {
46986
- const mn = (idx, fb = 0) => {
46987
- const r = params.cosDoc.resolve(pmArr.items[idx]);
46988
- return r?.kind === "number" ? r.value : fb;
46989
- };
46990
- patMatrix = [mn(0, 1), mn(1, 0), mn(2, 0), mn(3, 1), mn(4, 0), mn(5, 0)];
46991
- }
46992
- const patClip = st.clipRect ? [
46993
- Math.max(st.clipRect[0], pMinX),
46994
- Math.max(st.clipRect[1], pMinY),
46995
- Math.min(st.clipRect[2], pMaxX),
46996
- Math.min(st.clipRect[3], pMaxY)
46997
- ] : [pMinX, pMinY, pMaxX, pMaxY];
46998
- const shImg = renderShadingDictToImage(
46999
- params.cosDoc,
47000
- shDict,
47001
- patMatrix,
47002
- patClip,
47003
- st.fillAlpha,
47004
- "PatternShading_" + st.fillPatternName,
47005
- patClip,
47006
- shading?.kind === "stream" ? shading : void 0,
47007
- st.blendMode
47008
- );
47009
- if (shImg) {
47010
- emit({ kind: "image", value: shImg });
47011
- evaluatedFillPattern = true;
47012
- }
47013
- }
47014
- }
47015
- } else if (patNode?.kind === "stream") {
47016
- let pMinX = Infinity, pMinY = Infinity, pMaxX = -Infinity, pMaxY = -Infinity;
47017
- for (const s of transformedSegments) {
47018
- if (s.kind === "move" || s.kind === "line") {
47019
- pMinX = Math.min(pMinX, s.x);
47020
- pMinY = Math.min(pMinY, s.y);
47021
- pMaxX = Math.max(pMaxX, s.x);
47022
- pMaxY = Math.max(pMaxY, s.y);
47023
- } else if (s.kind === "cubic") {
47024
- pMinX = Math.min(pMinX, s.x1, s.x2, s.x);
47025
- pMinY = Math.min(pMinY, s.y1, s.y2, s.y);
47026
- pMaxX = Math.max(pMaxX, s.x1, s.x2, s.x);
47027
- pMaxY = Math.max(pMaxY, s.y1, s.y2, s.y);
47028
- } else if (s.kind === "rect") {
47029
- pMinX = Math.min(pMinX, s.x);
47030
- pMinY = Math.min(pMinY, s.y);
47031
- pMaxX = Math.max(pMaxX, s.x + s.width);
47032
- pMaxY = Math.max(pMaxY, s.y + s.height);
47033
- }
47034
- }
47035
- if (Number.isFinite(pMinX) && Number.isFinite(pMinY) && pMaxX > pMinX && pMaxY > pMinY) {
47036
- const xsNode = params.cosDoc.resolve(dictGet(patNode.dict, "XStep"));
47037
- const ysNode = params.cosDoc.resolve(dictGet(patNode.dict, "YStep"));
47038
- const xStep = xsNode?.kind === "number" && Math.abs(xsNode.value) > 1e-3 ? Math.abs(xsNode.value) : 40;
47039
- const yStep = ysNode?.kind === "number" && Math.abs(ysNode.value) > 1e-3 ? Math.abs(ysNode.value) : 40;
47040
- let patMatrix = [1, 0, 0, 1, 0, 0];
47041
- const pmArr = params.cosDoc.resolveArray(dictGet(patNode.dict, "Matrix"));
47042
- if (pmArr && pmArr.items.length >= 6) {
47043
- const mn = (idx, fb = 0) => {
47044
- const r = params.cosDoc.resolve(pmArr.items[idx]);
47045
- return r?.kind === "number" ? r.value : fb;
47046
- };
47047
- patMatrix = [mn(0, 1), mn(1, 0), mn(2, 0), mn(3, 1), mn(4, 0), mn(5, 0)];
47048
- }
47049
- const tileClip = st.clipRect ? [
47050
- Math.max(st.clipRect[0], pMinX),
47051
- Math.max(st.clipRect[1], pMinY),
47052
- Math.min(st.clipRect[2], pMaxX),
47053
- Math.min(st.clipRect[3], pMaxY)
47054
- ] : [pMinX, pMinY, pMaxX, pMaxY];
47055
- const patNodes = parseContentStream(params.cosDoc.decodeStream(patNode));
47056
- const patResDict = params.cosDoc.resolveDict(dictGet(patNode.dict, "Resources")) ?? activeResources;
47057
- const patFonts = new Map(activeFonts);
47058
- for (const [fk, fv] of resolvePageFonts(params.cosDoc, patResDict).entries()) {
47059
- patFonts.set(fk, fv);
47060
- }
47061
- const ixStart = Math.floor(pMinX / xStep);
47062
- const ixEnd = Math.min(ixStart + 8, Math.ceil(pMaxX / xStep) - 1);
47063
- const iyStart = Math.floor(pMinY / yStep);
47064
- const iyEnd = Math.min(iyStart + 8, Math.ceil(pMaxY / yStep) - 1);
47065
- for (let iy = iyStart; iy <= iyEnd; iy++) {
47066
- for (let ix = ixStart; ix <= ixEnd; ix++) {
47067
- const tileCtm = multiplyMatrices([1, 0, 0, 1, ix * xStep, iy * yStep], patMatrix);
47068
- stateStack.push({
47069
- ...st,
47070
- fillPatternName: void 0,
47071
- ctm: tileCtm,
47072
- clipRect: tileClip
47073
- });
47074
- walkNodes(patNodes, mcid, actualText, patResDict, patFonts, depth + 1);
47075
- if (stateStack.length > 1) stateStack.pop();
47076
- }
47077
- }
47078
- evaluatedFillPattern = true;
47079
- }
47080
- }
47081
- }
47079
+ const evaluatedFillPattern = isFill && paintPattern(
47080
+ transformedSegments,
47081
+ node.paint.includes("*") ? "evenodd" : "nonzero",
47082
+ activeResources,
47083
+ activeFonts,
47084
+ depth,
47085
+ mcid,
47086
+ actualText
47087
+ );
47082
47088
  if (evaluatedFillPattern && !isStroke) {
47083
47089
  applyClip();
47084
47090
  break;
@@ -47279,10 +47285,19 @@ function evaluateContentStreamToDisplayList(params) {
47279
47285
  if (st.textRenderMode >= 4 && st.textRenderMode <= 7) pendingTextClip.push(...transformedGlyphSegs);
47280
47286
  const isFillGlyph = st.textRenderMode === 0 || st.textRenderMode === 2 || st.textRenderMode === 4 || st.textRenderMode === 6;
47281
47287
  const isStrokeGlyph = st.textRenderMode === 1 || st.textRenderMode === 2 || st.textRenderMode === 5 || st.textRenderMode === 6;
47288
+ const patterned = isFillGlyph && paintPattern(
47289
+ transformedGlyphSegs,
47290
+ "nonzero",
47291
+ activeResources,
47292
+ activeFonts,
47293
+ depth,
47294
+ mcid,
47295
+ actualText
47296
+ );
47282
47297
  const paint = {
47283
47298
  segments: transformedGlyphSegs,
47284
- fillColor: isFillGlyph ? st.fillColor : void 0,
47285
- fillAlpha: isFillGlyph ? st.fillAlpha : void 0,
47299
+ fillColor: isFillGlyph && !patterned ? st.fillColor : void 0,
47300
+ fillAlpha: isFillGlyph && !patterned ? st.fillAlpha : void 0,
47286
47301
  strokeColor: isStrokeGlyph ? st.strokeColor : void 0,
47287
47302
  strokeAlpha: isStrokeGlyph ? st.strokeAlpha : void 0,
47288
47303
  strokeWidth: isStrokeGlyph ? st.strokeWidth : 0,
@@ -50526,10 +50541,14 @@ function computePdfBlendRgb(cbR, cbG, cbB, csR, csG, csB, mode) {
50526
50541
  blendChannelSeparable(cbB, csB, mode)
50527
50542
  ];
50528
50543
  }
50529
- function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMask) {
50544
+ function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMask, groupAlpha) {
50530
50545
  if (px < 0 || py < 0 || px >= width || py >= height || alpha <= 0) return;
50531
50546
  const a = Math.min(1, Math.max(0, alpha)) * (clipMask ? clipMask[(py * width + px) * 4 + 3] / 255 : 1);
50532
50547
  const idx = (py * width + px) * 4;
50548
+ if (groupAlpha) {
50549
+ const pixel = py * width + px;
50550
+ groupAlpha[pixel] = a + groupAlpha[pixel] * (1 - a);
50551
+ }
50533
50552
  const csR = Math.min(1, Math.max(0, color.r));
50534
50553
  const csG = Math.min(1, Math.max(0, color.g));
50535
50554
  const csB = Math.min(1, Math.max(0, color.b));
@@ -50661,7 +50680,7 @@ function pathsToEdges(paths, closeSubpaths = false) {
50661
50680
  }
50662
50681
  return edges;
50663
50682
  }
50664
- function fillEdgesScanline4x4(rgba, width, height, edges, color, alpha = 1, fillRule = "nonzero", clipScreen, antialias = true, blendMode, clipMask) {
50683
+ function fillEdgesScanline4x4(rgba, width, height, edges, color, alpha = 1, fillRule = "nonzero", clipScreen, antialias = true, blendMode, clipMask, groupAlpha) {
50665
50684
  if (edges.length === 0) return;
50666
50685
  let minY = Infinity;
50667
50686
  let maxY = -Infinity;
@@ -50727,7 +50746,7 @@ function fillEdgesScanline4x4(rgba, width, height, edges, color, alpha = 1, fill
50727
50746
  const count = rowCounts[px];
50728
50747
  if (count > 0) {
50729
50748
  const cov = antialias ? count / 16 : count >= 8 ? 1 : 0;
50730
- blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
50749
+ blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask, groupAlpha);
50731
50750
  }
50732
50751
  }
50733
50752
  }
@@ -50806,19 +50825,16 @@ function hasCompositingEffects(operations, includeSoftMasks = false) {
50806
50825
  return operations.some((operation) => includeSoftMasks && !!operation.value.softMask || !!operation.value.blendMode && operation.value.blendMode !== "Normal" && operation.value.blendMode !== "Compatible" || operation.kind === "group" && hasCompositingEffects(operation.value.operations, includeSoftMasks));
50807
50826
  }
50808
50827
  function needsGroupBackdrop(group) {
50809
- return group.isolated === false && !!group.softMask && hasCompositingEffects(group.operations, true);
50828
+ return group.isolated === false && hasCompositingEffects(group.operations, true);
50810
50829
  }
50811
- function renderDisplayListToBitmap(displayList, options = {}) {
50812
- const baseScale = options.scale ?? (options.dpi ? options.dpi / 72 : 1.5);
50813
- const scaleX = options.dpiX !== void 0 ? options.dpiX / 72 : baseScale;
50814
- const scaleY = options.dpiY !== void 0 ? options.dpiY / 72 : baseScale;
50815
- const scale = scaleX;
50830
+ function renderDisplayListLayer(displayList, options, scale, backdrop) {
50816
50831
  const [originX, originY] = displayList.origin ?? [0, 0];
50817
50832
  const pageTop = originY + displayList.height;
50818
50833
  const toScreen = (x, y) => [(x - originX) * scale, (pageTop - y) * scale];
50819
50834
  const width = Math.max(1, Math.round(displayList.width * scale));
50820
50835
  const height = Math.max(1, Math.round(displayList.height * scale));
50821
- const rgba = new Uint8Array(width * height * 4);
50836
+ const rgba = backdrop ? backdrop.slice() : new Uint8Array(width * height * 4);
50837
+ const groupAlpha = backdrop ? new Float32Array(width * height) : void 0;
50822
50838
  const deferBackground = !options.transparent && hasCompositingEffects(paintOperations(displayList));
50823
50839
  const transparent = options.transparent || deferBackground;
50824
50840
  const bg = options.background ?? { r: 1, g: 1, b: 1 };
@@ -50826,7 +50842,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
50826
50842
  const bgG = transparent ? 0 : Math.round(bg.g * 255);
50827
50843
  const bgB = transparent ? 0 : Math.round(bg.b * 255);
50828
50844
  const bgA = transparent ? 0 : 255;
50829
- for (let i = 0; i < width * height; i++) {
50845
+ for (let i = 0; !backdrop && i < width * height; i++) {
50830
50846
  rgba[i * 4] = bgR;
50831
50847
  rgba[i * 4 + 1] = bgG;
50832
50848
  rgba[i * 4 + 2] = bgB;
@@ -50844,20 +50860,12 @@ function renderDisplayListToBitmap(displayList, options = {}) {
50844
50860
  let operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
50845
50861
  if (operation.kind === "group") {
50846
50862
  const group = operation.value;
50847
- let operations = group.operations;
50848
- if (needsGroupBackdrop(group)) {
50849
- operations = [{ kind: "image", value: {
50850
- name: "GroupBackdrop",
50851
- width,
50852
- height,
50853
- decodedRgba: rgba.slice(),
50854
- matrix: [width / scale, 0, 0, height / scale, originX, pageTop - height / scale],
50855
- colorSpace: "DeviceRGB",
50856
- bitsPerComponent: 8,
50857
- ...group.bboxClip ? { clipPaths: [group.bboxClip] } : {}
50858
- } }, ...operations];
50859
- }
50860
- const bitmap = renderDisplayListToBitmap({ ...displayList, rotation: 0, operations }, { ...options, scale, dpiX: void 0, dpiY: void 0, cropRect: void 0, useCropBox: false, transparent: true });
50863
+ const bitmap = renderDisplayListLayer(
50864
+ { ...displayList, operations: group.operations },
50865
+ { ...options, transparent: true },
50866
+ scale,
50867
+ needsGroupBackdrop(group) ? rgba : void 0
50868
+ );
50861
50869
  for (let i = 3; i < bitmap.data.length; i += 4) bitmap.data[i] = Math.round(bitmap.data[i] * group.alpha);
50862
50870
  operation = { kind: "image", value: {
50863
50871
  name: "TransparencyGroup",
@@ -50927,7 +50935,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
50927
50935
  if (path.fillColor) {
50928
50936
  const edges = pathsToEdges(segmentsToScreenPaths(path.segments, displayList.height, scale, toScreen), true);
50929
50937
  const clipScreen = path.clipRect ? [(path.clipRect[0] - originX) * scale, (pageTop - path.clipRect[3]) * scale, (path.clipRect[2] - originX) * scale, (pageTop - path.clipRect[1]) * scale] : void 0;
50930
- fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
50938
+ fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask, groupAlpha);
50931
50939
  }
50932
50940
  if (path.strokeColor) {
50933
50941
  const rawSw = path.strokeWidth * scale * (path.strokeMatrix ? Math.hypot(path.strokeMatrix[0], path.strokeMatrix[1]) : 1);
@@ -50945,7 +50953,8 @@ function renderDisplayListToBitmap(displayList, options = {}) {
50945
50953
  clipScreen,
50946
50954
  original.kind === "glyph" ? aaTxt : aaVec,
50947
50955
  path.blendMode,
50948
- clipMask
50956
+ clipMask,
50957
+ groupAlpha
50949
50958
  );
50950
50959
  }
50951
50960
  } else if (operation.kind === "image") {
@@ -51009,12 +51018,31 @@ function renderDisplayListToBitmap(displayList, options = {}) {
51009
51018
  },
51010
51019
  sample[3] / 255,
51011
51020
  img.blendMode,
51012
- clipMask
51021
+ clipMask,
51022
+ groupAlpha
51013
51023
  );
51014
51024
  }
51015
51025
  }
51016
51026
  }
51017
51027
  }
51028
+ if (backdrop && groupAlpha) {
51029
+ for (let i = 0; i < rgba.length; i += 4) {
51030
+ const alpha = groupAlpha[i / 4];
51031
+ if (alpha === 0) {
51032
+ rgba.fill(0, i, i + 4);
51033
+ continue;
51034
+ }
51035
+ const factor = backdrop[i + 3] / 255 * (1 / alpha - 1);
51036
+ for (let channel = 0; channel < 3; channel++) {
51037
+ const color = rgba[i + channel];
51038
+ rgba[i + channel] = Math.max(0, Math.min(
51039
+ 255,
51040
+ Math.round(color + (color - backdrop[i + channel]) * factor)
51041
+ ));
51042
+ }
51043
+ rgba[i + 3] = Math.round(alpha * 255);
51044
+ }
51045
+ }
51018
51046
  if (deferBackground) {
51019
51047
  for (let i = 0; i < rgba.length; i += 4) {
51020
51048
  const alpha = rgba[i + 3] / 255;
@@ -51024,7 +51052,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
51024
51052
  rgba[i + 3] = 255;
51025
51053
  }
51026
51054
  }
51027
- let result = { width, height, data: rgba };
51055
+ return { width, height, data: rgba };
51056
+ }
51057
+ function renderDisplayListToBitmap(displayList, options = {}) {
51058
+ const baseScale = options.scale ?? (options.dpi ? options.dpi / 72 : 1.5);
51059
+ const scaleX = options.dpiX !== void 0 ? options.dpiX / 72 : baseScale;
51060
+ const scaleY = options.dpiY !== void 0 ? options.dpiY / 72 : baseScale;
51061
+ let result = renderDisplayListLayer(displayList, options, scaleX);
51062
+ const { width, height, data: rgba } = result;
51028
51063
  if (Math.abs(scaleX - scaleY) > 1e-6) {
51029
51064
  const targetW = Math.max(1, Math.round(displayList.width * scaleX));
51030
51065
  const targetH = Math.max(1, Math.round(displayList.height * scaleY));