@poe-platform/safe-bash 0.1.773 → 0.1.774

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 (31) hide show
  1. package/dist/image-ast/index.browser.js +742 -150
  2. package/dist/image-ast/index.js +742 -150
  3. package/dist/pdf-ast/index.js +742 -150
  4. package/dist/pdf-ast/vendor/pdfjs-fonts.d.mts +12 -0
  5. package/dist/pdf-ast/vendor/pdfjs-fonts.mjs +702 -0
  6. package/dist/safe-bash/command-chunks/{chunk-5VXZSNM2.js → chunk-4ZHDCMQX.js} +2 -2
  7. package/dist/safe-bash/command-chunks/{chunk-G3NVK25P.js → chunk-HH5QPKIN.js} +1 -1
  8. package/dist/safe-bash/command-chunks/{chunk-B2MM5DIT.js → chunk-PM63UJE6.js} +742 -150
  9. package/dist/safe-bash/core.browser.js +63 -7
  10. package/dist/safe-bash/shell/runtime.js +17 -9
  11. package/dist/safe-bash/shell/sync-posix-regex.d.ts +3 -0
  12. package/dist/safe-bash/shell/sync-posix-regex.js +48 -0
  13. package/dist/safe-bash-command-ffmpeg/index.js +7250 -7046
  14. package/dist/safe-bash-command-gpg/index.js +28 -7
  15. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  16. package/dist/safe-bash-command-openssl/index.js +24 -6
  17. package/dist/safe-bash-command-pandoc/command.js +3 -3
  18. package/dist/safe-bash-command-pandoc/index.js +3 -3
  19. package/dist/safe-bash-command-pdfimages/index.js +742 -150
  20. package/dist/safe-bash-command-pdfinfo/index.js +742 -150
  21. package/dist/safe-bash-command-pdftk/index.js +742 -150
  22. package/dist/safe-bash-command-pdftoppm/index.js +742 -150
  23. package/dist/safe-bash-command-pdftotext/index.js +742 -150
  24. package/dist/safe-bash-command-qpdf/index.js +742 -150
  25. package/dist/safe-bash-command-sips/index.js +2 -2
  26. package/dist/safe-bash-command-soffice/index.js +1 -1
  27. package/dist/safe-bash-command-ssconvert/index.js +742 -150
  28. package/dist/safe-bash-command-ssh/index.js +124 -23
  29. package/dist/safe-bash-command-wkhtmltopdf/index.js +748 -150
  30. package/package.json +2 -2
  31. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +22 -0
@@ -177092,6 +177092,11 @@ var FONT_IDENTITY_MATRIX = [1e-3, 0, 0, 1e-3, 0, 0];
177092
177092
  var LINE_FACTOR = 1.35;
177093
177093
  var LINE_DESCENT_FACTOR = 0.35;
177094
177094
  var BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
177095
+ var MeshFigureType = {
177096
+ TRIANGLES: 1,
177097
+ LATTICE: 2,
177098
+ PATCH: 3
177099
+ };
177095
177100
  var VerbosityLevel = {
177096
177101
  ERRORS: 0,
177097
177102
  WARNINGS: 1,
@@ -198624,6 +198629,700 @@ function buildPostScriptJsFunction(source, domain, range3, forceInterpreter = fa
198624
198629
  }
198625
198630
  return PSStackBasedInterpreter.build(program, domain, range3);
198626
198631
  }
198632
+ var ShadingType = {
198633
+ FUNCTION_BASED: 1,
198634
+ AXIAL: 2,
198635
+ RADIAL: 3,
198636
+ FREE_FORM_MESH: 4,
198637
+ LATTICE_FORM_MESH: 5,
198638
+ COONS_PATCH_MESH: 6,
198639
+ TENSOR_PATCH_MESH: 7
198640
+ };
198641
+ var BaseShading = class _BaseShading {
198642
+ // A small number to offset the first/last color stops so we can insert ones
198643
+ // to support extend. Number.MIN_VALUE is too small and breaks the extend.
198644
+ static SMALL_NUMBER = 1e-6;
198645
+ constructor() {
198646
+ if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && this.constructor === _BaseShading) {
198647
+ unreachable2("Cannot initialize BaseShading.");
198648
+ }
198649
+ }
198650
+ getIR() {
198651
+ unreachable2("Abstract method `getIR` called.");
198652
+ }
198653
+ };
198654
+ function meshUpdateBounds(self2) {
198655
+ let minX = self2.coords[0][0], minY = self2.coords[0][1], maxX = minX, maxY = minY;
198656
+ for (let i = 1, ii = self2.coords.length; i < ii; i++) {
198657
+ const x = self2.coords[i][0], y = self2.coords[i][1];
198658
+ minX = minX > x ? x : minX;
198659
+ minY = minY > y ? y : minY;
198660
+ maxX = maxX < x ? x : maxX;
198661
+ maxY = maxY < y ? y : maxY;
198662
+ }
198663
+ self2.bounds = [minX, minY, maxX, maxY];
198664
+ }
198665
+ function meshPackData(self2) {
198666
+ let i, j, ii;
198667
+ const coords = self2.coords;
198668
+ const coordsPacked = new Float32Array(coords.length * 2);
198669
+ for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
198670
+ const xy = coords[i];
198671
+ coordsPacked[j++] = xy[0];
198672
+ coordsPacked[j++] = xy[1];
198673
+ }
198674
+ self2.coords = coordsPacked;
198675
+ const colors2 = self2.colors;
198676
+ const colorsPacked = new Uint8Array(colors2.length * 4);
198677
+ for (i = 0, j = 0, ii = colors2.length; i < ii; i++) {
198678
+ const c4 = colors2[i];
198679
+ colorsPacked[j++] = c4[0];
198680
+ colorsPacked[j++] = c4[1];
198681
+ colorsPacked[j++] = c4[2];
198682
+ j++;
198683
+ }
198684
+ self2.colors = colorsPacked;
198685
+ for (const figure of self2.figures) {
198686
+ figure.coords = new Uint32Array(figure.coords);
198687
+ figure.colors = new Uint32Array(figure.colors);
198688
+ }
198689
+ }
198690
+ function buildMeshVertexData(coords, colors2, figures) {
198691
+ let vertexCount = 0;
198692
+ for (const figure of figures) {
198693
+ if (figure.type === MeshFigureType.TRIANGLES) {
198694
+ vertexCount += figure.coords.length;
198695
+ } else if (figure.type === MeshFigureType.LATTICE) {
198696
+ const vpr = figure.verticesPerRow;
198697
+ vertexCount += (Math.floor(figure.coords.length / vpr) - 1) * (vpr - 1) * 6;
198698
+ }
198699
+ }
198700
+ const posData = new Float32Array(vertexCount * 2);
198701
+ const colData = new Uint8Array(vertexCount * 4);
198702
+ let pOff = 0, cOff = 0;
198703
+ const addVertex = (pi2, ci) => {
198704
+ posData[pOff++] = coords[pi2 * 2];
198705
+ posData[pOff++] = coords[pi2 * 2 + 1];
198706
+ colData[cOff++] = colors2[ci * 4];
198707
+ colData[cOff++] = colors2[ci * 4 + 1];
198708
+ colData[cOff++] = colors2[ci * 4 + 2];
198709
+ cOff++;
198710
+ };
198711
+ for (const figure of figures) {
198712
+ const ps = figure.coords;
198713
+ const cs = figure.colors;
198714
+ if (figure.type === MeshFigureType.TRIANGLES) {
198715
+ for (let i = 0, ii = ps.length; i < ii; i++) {
198716
+ addVertex(ps[i], cs[i]);
198717
+ }
198718
+ } else if (figure.type === MeshFigureType.LATTICE) {
198719
+ const vpr = figure.verticesPerRow;
198720
+ const rows = Math.floor(ps.length / vpr) - 1;
198721
+ const cols = vpr - 1;
198722
+ for (let i = 0; i < rows; i++) {
198723
+ let q2 = i * vpr;
198724
+ for (let j = 0; j < cols; j++, q2++) {
198725
+ addVertex(ps[q2], cs[q2]);
198726
+ addVertex(ps[q2 + 1], cs[q2 + 1]);
198727
+ addVertex(ps[q2 + vpr], cs[q2 + vpr]);
198728
+ addVertex(ps[q2 + vpr + 1], cs[q2 + vpr + 1]);
198729
+ addVertex(ps[q2 + 1], cs[q2 + 1]);
198730
+ addVertex(ps[q2 + vpr], cs[q2 + vpr]);
198731
+ }
198732
+ }
198733
+ }
198734
+ }
198735
+ return { posData, colData, vertexCount };
198736
+ }
198737
+ var MeshStreamReader = class {
198738
+ constructor(stream, context) {
198739
+ this.stream = stream;
198740
+ this.context = context;
198741
+ this.buffer = 0;
198742
+ this.bufferLength = 0;
198743
+ const numComps = context.numComps;
198744
+ this.tmpCompsBuf = new Float32Array(numComps);
198745
+ const csNumComps = context.colorSpace.numComps;
198746
+ this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
198747
+ }
198748
+ get hasData() {
198749
+ if (this.stream.end) {
198750
+ return this.stream.pos < this.stream.end;
198751
+ }
198752
+ if (this.bufferLength > 0) {
198753
+ return true;
198754
+ }
198755
+ const nextByte = this.stream.getByte();
198756
+ if (nextByte < 0) {
198757
+ return false;
198758
+ }
198759
+ this.buffer = nextByte;
198760
+ this.bufferLength = 8;
198761
+ return true;
198762
+ }
198763
+ readBits(n) {
198764
+ const { stream } = this;
198765
+ let { buffer, bufferLength } = this;
198766
+ if (n === 32) {
198767
+ if (bufferLength === 0) {
198768
+ return stream.getInt32() >>> 0;
198769
+ }
198770
+ buffer = buffer << 24 | stream.getByte() << 16 | stream.getByte() << 8 | stream.getByte();
198771
+ const nextByte = stream.getByte();
198772
+ this.buffer = nextByte & (1 << bufferLength) - 1;
198773
+ return (buffer << 8 - bufferLength | (nextByte & 255) >> bufferLength) >>> 0;
198774
+ }
198775
+ if (n === 8 && bufferLength === 0) {
198776
+ return stream.getByte();
198777
+ }
198778
+ while (bufferLength < n) {
198779
+ buffer = buffer << 8 | stream.getByte();
198780
+ bufferLength += 8;
198781
+ }
198782
+ bufferLength -= n;
198783
+ this.bufferLength = bufferLength;
198784
+ this.buffer = buffer & (1 << bufferLength) - 1;
198785
+ return buffer >> bufferLength;
198786
+ }
198787
+ align() {
198788
+ this.buffer = 0;
198789
+ this.bufferLength = 0;
198790
+ }
198791
+ readFlag() {
198792
+ return this.readBits(this.context.bitsPerFlag);
198793
+ }
198794
+ readCoordinate() {
198795
+ const { bitsPerCoordinate, decode: decode3 } = this.context;
198796
+ const xi = this.readBits(bitsPerCoordinate);
198797
+ const yi = this.readBits(bitsPerCoordinate);
198798
+ const scale2 = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 23283064365386963e-26;
198799
+ return [
198800
+ xi * scale2 * (decode3[1] - decode3[0]) + decode3[0],
198801
+ yi * scale2 * (decode3[3] - decode3[2]) + decode3[2]
198802
+ ];
198803
+ }
198804
+ readComponents() {
198805
+ const { bitsPerComponent, colorFn, colorSpace, decode: decode3, numComps } = this.context;
198806
+ const scale2 = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 23283064365386963e-26;
198807
+ const components22 = this.tmpCompsBuf;
198808
+ for (let i = 0, j = 4; i < numComps; i++, j += 2) {
198809
+ const ci = this.readBits(bitsPerComponent);
198810
+ components22[i] = ci * scale2 * (decode3[j + 1] - decode3[j]) + decode3[j];
198811
+ }
198812
+ const color5 = this.tmpCsCompsBuf;
198813
+ colorFn?.(components22, 0, color5, 0);
198814
+ return colorSpace.getRgb(color5, 0);
198815
+ }
198816
+ };
198817
+ var bCache = null;
198818
+ function getB(count) {
198819
+ if (bCache?.has(count)) return bCache.get(count);
198820
+ const values2 = Array.from({ length: count + 1 }, (_, i) => {
198821
+ const t = i / count, t_ = 1 - t;
198822
+ return new Float32Array([
198823
+ t_ ** 3,
198824
+ 3 * t * t_ ** 2,
198825
+ 3 * t ** 2 * t_,
198826
+ t ** 3
198827
+ ]);
198828
+ });
198829
+ (bCache ??= /* @__PURE__ */ new Map()).set(count, values2);
198830
+ return values2;
198831
+ }
198832
+ var MeshShading = class _MeshShading extends BaseShading {
198833
+ static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
198834
+ static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
198835
+ // Count of triangles per entire mesh bounds.
198836
+ static TRIANGLE_DENSITY = 20;
198837
+ constructor(shadingType, stream, context, rowVertices) {
198838
+ super();
198839
+ this.shadingType = shadingType;
198840
+ this.bbox = this.background = null;
198841
+ this.coords = [];
198842
+ this.colors = [];
198843
+ this.figures = [];
198844
+ const reader = new MeshStreamReader(stream, context);
198845
+ let patchMesh = false;
198846
+ switch (this.shadingType) {
198847
+ case ShadingType.FREE_FORM_MESH:
198848
+ this._decodeType4Shading(reader);
198849
+ break;
198850
+ case ShadingType.LATTICE_FORM_MESH:
198851
+ const verticesPerRow = rowVertices | 0;
198852
+ if (verticesPerRow < 2) {
198853
+ throw new FormatError("Invalid VerticesPerRow");
198854
+ }
198855
+ this._decodeType5Shading(reader, verticesPerRow);
198856
+ break;
198857
+ case ShadingType.COONS_PATCH_MESH:
198858
+ this._decodeType6Shading(reader);
198859
+ patchMesh = true;
198860
+ break;
198861
+ case ShadingType.TENSOR_PATCH_MESH:
198862
+ this._decodeType7Shading(reader);
198863
+ patchMesh = true;
198864
+ break;
198865
+ default:
198866
+ unreachable2("Unsupported mesh type.");
198867
+ break;
198868
+ }
198869
+ if (patchMesh) {
198870
+ this._updateBounds();
198871
+ for (let i = 0, ii = this.figures.length; i < ii; i++) {
198872
+ this._buildFigureFromPatch(i);
198873
+ }
198874
+ }
198875
+ this._updateBounds();
198876
+ this._packData();
198877
+ }
198878
+ _decodeType4Shading(reader) {
198879
+ const coords = this.coords;
198880
+ const colors2 = this.colors;
198881
+ const operators2 = [];
198882
+ const ps = [];
198883
+ let verticesLeft = 0;
198884
+ while (reader.hasData) {
198885
+ const f2 = reader.readFlag();
198886
+ const coord2 = reader.readCoordinate();
198887
+ const color5 = reader.readComponents();
198888
+ if (verticesLeft === 0) {
198889
+ if (!(0 <= f2 && f2 <= 2)) {
198890
+ throw new FormatError("Unknown type4 flag");
198891
+ }
198892
+ switch (f2) {
198893
+ case 0:
198894
+ verticesLeft = 3;
198895
+ break;
198896
+ case 1:
198897
+ ps.push(ps.at(-2), ps.at(-1));
198898
+ verticesLeft = 1;
198899
+ break;
198900
+ case 2:
198901
+ ps.push(ps.at(-3), ps.at(-1));
198902
+ verticesLeft = 1;
198903
+ break;
198904
+ }
198905
+ operators2.push(f2);
198906
+ }
198907
+ ps.push(coords.length);
198908
+ coords.push(coord2);
198909
+ colors2.push(color5);
198910
+ verticesLeft--;
198911
+ reader.align();
198912
+ }
198913
+ this.figures.push({
198914
+ type: MeshFigureType.TRIANGLES,
198915
+ coords: new Int32Array(ps),
198916
+ colors: new Int32Array(ps)
198917
+ });
198918
+ }
198919
+ _decodeType5Shading(reader, verticesPerRow) {
198920
+ const coords = this.coords;
198921
+ const colors2 = this.colors;
198922
+ const ps = [];
198923
+ while (reader.hasData) {
198924
+ const coord2 = reader.readCoordinate();
198925
+ const color5 = reader.readComponents();
198926
+ ps.push(coords.length);
198927
+ coords.push(coord2);
198928
+ colors2.push(color5);
198929
+ }
198930
+ this.figures.push({
198931
+ type: MeshFigureType.LATTICE,
198932
+ coords: new Int32Array(ps),
198933
+ colors: new Int32Array(ps),
198934
+ verticesPerRow
198935
+ });
198936
+ }
198937
+ _decodeType6Shading(reader) {
198938
+ const coords = this.coords;
198939
+ const colors2 = this.colors;
198940
+ const ps = new Int32Array(16);
198941
+ const cs = new Int32Array(4);
198942
+ while (reader.hasData) {
198943
+ const f2 = reader.readFlag();
198944
+ if (!(0 <= f2 && f2 <= 3)) {
198945
+ throw new FormatError("Unknown type6 flag");
198946
+ }
198947
+ const pi2 = coords.length;
198948
+ for (let i = 0, ii = f2 !== 0 ? 8 : 12; i < ii; i++) {
198949
+ coords.push(reader.readCoordinate());
198950
+ }
198951
+ const ci = colors2.length;
198952
+ for (let i = 0, ii = f2 !== 0 ? 2 : 4; i < ii; i++) {
198953
+ colors2.push(reader.readComponents());
198954
+ }
198955
+ let tmp1, tmp2, tmp3, tmp4;
198956
+ switch (f2) {
198957
+ // prettier-ignore
198958
+ case 0:
198959
+ ps[12] = pi2 + 3;
198960
+ ps[13] = pi2 + 4;
198961
+ ps[14] = pi2 + 5;
198962
+ ps[15] = pi2 + 6;
198963
+ ps[8] = pi2 + 2;
198964
+ ps[11] = pi2 + 7;
198965
+ ps[4] = pi2 + 1;
198966
+ ps[7] = pi2 + 8;
198967
+ ps[0] = pi2;
198968
+ ps[1] = pi2 + 11;
198969
+ ps[2] = pi2 + 10;
198970
+ ps[3] = pi2 + 9;
198971
+ cs[2] = ci + 1;
198972
+ cs[3] = ci + 2;
198973
+ cs[0] = ci;
198974
+ cs[1] = ci + 3;
198975
+ break;
198976
+ // prettier-ignore
198977
+ case 1:
198978
+ tmp1 = ps[12];
198979
+ tmp2 = ps[13];
198980
+ tmp3 = ps[14];
198981
+ tmp4 = ps[15];
198982
+ ps[12] = tmp4;
198983
+ ps[13] = pi2 + 0;
198984
+ ps[14] = pi2 + 1;
198985
+ ps[15] = pi2 + 2;
198986
+ ps[8] = tmp3;
198987
+ ps[11] = pi2 + 3;
198988
+ ps[4] = tmp2;
198989
+ ps[7] = pi2 + 4;
198990
+ ps[0] = tmp1;
198991
+ ps[1] = pi2 + 7;
198992
+ ps[2] = pi2 + 6;
198993
+ ps[3] = pi2 + 5;
198994
+ tmp1 = cs[2];
198995
+ tmp2 = cs[3];
198996
+ cs[2] = tmp2;
198997
+ cs[3] = ci;
198998
+ cs[0] = tmp1;
198999
+ cs[1] = ci + 1;
199000
+ break;
199001
+ // prettier-ignore
199002
+ case 2:
199003
+ tmp1 = ps[15];
199004
+ tmp2 = ps[11];
199005
+ ps[12] = ps[3];
199006
+ ps[13] = pi2 + 0;
199007
+ ps[14] = pi2 + 1;
199008
+ ps[15] = pi2 + 2;
199009
+ ps[8] = ps[7];
199010
+ ps[11] = pi2 + 3;
199011
+ ps[4] = tmp2;
199012
+ ps[7] = pi2 + 4;
199013
+ ps[0] = tmp1;
199014
+ ps[1] = pi2 + 7;
199015
+ ps[2] = pi2 + 6;
199016
+ ps[3] = pi2 + 5;
199017
+ tmp1 = cs[3];
199018
+ cs[2] = cs[1];
199019
+ cs[3] = ci;
199020
+ cs[0] = tmp1;
199021
+ cs[1] = ci + 1;
199022
+ break;
199023
+ // prettier-ignore
199024
+ case 3:
199025
+ ps[12] = ps[0];
199026
+ ps[13] = pi2 + 0;
199027
+ ps[14] = pi2 + 1;
199028
+ ps[15] = pi2 + 2;
199029
+ ps[8] = ps[1];
199030
+ ps[11] = pi2 + 3;
199031
+ ps[4] = ps[2];
199032
+ ps[7] = pi2 + 4;
199033
+ ps[0] = ps[3];
199034
+ ps[1] = pi2 + 7;
199035
+ ps[2] = pi2 + 6;
199036
+ ps[3] = pi2 + 5;
199037
+ cs[2] = cs[0];
199038
+ cs[3] = ci;
199039
+ cs[0] = cs[1];
199040
+ cs[1] = ci + 1;
199041
+ break;
199042
+ }
199043
+ ps[5] = coords.length;
199044
+ coords.push([
199045
+ (-4 * coords[ps[0]][0] - coords[ps[15]][0] + 6 * (coords[ps[4]][0] + coords[ps[1]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
199046
+ (-4 * coords[ps[0]][1] - coords[ps[15]][1] + 6 * (coords[ps[4]][1] + coords[ps[1]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
199047
+ ]);
199048
+ ps[6] = coords.length;
199049
+ coords.push([
199050
+ (-4 * coords[ps[3]][0] - coords[ps[12]][0] + 6 * (coords[ps[2]][0] + coords[ps[7]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
199051
+ (-4 * coords[ps[3]][1] - coords[ps[12]][1] + 6 * (coords[ps[2]][1] + coords[ps[7]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
199052
+ ]);
199053
+ ps[9] = coords.length;
199054
+ coords.push([
199055
+ (-4 * coords[ps[12]][0] - coords[ps[3]][0] + 6 * (coords[ps[8]][0] + coords[ps[13]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
199056
+ (-4 * coords[ps[12]][1] - coords[ps[3]][1] + 6 * (coords[ps[8]][1] + coords[ps[13]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
199057
+ ]);
199058
+ ps[10] = coords.length;
199059
+ coords.push([
199060
+ (-4 * coords[ps[15]][0] - coords[ps[0]][0] + 6 * (coords[ps[11]][0] + coords[ps[14]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
199061
+ (-4 * coords[ps[15]][1] - coords[ps[0]][1] + 6 * (coords[ps[11]][1] + coords[ps[14]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
199062
+ ]);
199063
+ this.figures.push({
199064
+ type: MeshFigureType.PATCH,
199065
+ coords: new Int32Array(ps),
199066
+ // making copies of ps and cs
199067
+ colors: new Int32Array(cs)
199068
+ });
199069
+ }
199070
+ }
199071
+ _decodeType7Shading(reader) {
199072
+ const coords = this.coords;
199073
+ const colors2 = this.colors;
199074
+ const ps = new Int32Array(16);
199075
+ const cs = new Int32Array(4);
199076
+ while (reader.hasData) {
199077
+ const f2 = reader.readFlag();
199078
+ if (!(0 <= f2 && f2 <= 3)) {
199079
+ throw new FormatError("Unknown type7 flag");
199080
+ }
199081
+ const pi2 = coords.length;
199082
+ for (let i = 0, ii = f2 !== 0 ? 12 : 16; i < ii; i++) {
199083
+ coords.push(reader.readCoordinate());
199084
+ }
199085
+ const ci = colors2.length;
199086
+ for (let i = 0, ii = f2 !== 0 ? 2 : 4; i < ii; i++) {
199087
+ colors2.push(reader.readComponents());
199088
+ }
199089
+ let tmp1, tmp2, tmp3, tmp4;
199090
+ switch (f2) {
199091
+ // prettier-ignore
199092
+ case 0:
199093
+ ps[12] = pi2 + 3;
199094
+ ps[13] = pi2 + 4;
199095
+ ps[14] = pi2 + 5;
199096
+ ps[15] = pi2 + 6;
199097
+ ps[8] = pi2 + 2;
199098
+ ps[9] = pi2 + 13;
199099
+ ps[10] = pi2 + 14;
199100
+ ps[11] = pi2 + 7;
199101
+ ps[4] = pi2 + 1;
199102
+ ps[5] = pi2 + 12;
199103
+ ps[6] = pi2 + 15;
199104
+ ps[7] = pi2 + 8;
199105
+ ps[0] = pi2;
199106
+ ps[1] = pi2 + 11;
199107
+ ps[2] = pi2 + 10;
199108
+ ps[3] = pi2 + 9;
199109
+ cs[2] = ci + 1;
199110
+ cs[3] = ci + 2;
199111
+ cs[0] = ci;
199112
+ cs[1] = ci + 3;
199113
+ break;
199114
+ // prettier-ignore
199115
+ case 1:
199116
+ tmp1 = ps[12];
199117
+ tmp2 = ps[13];
199118
+ tmp3 = ps[14];
199119
+ tmp4 = ps[15];
199120
+ ps[12] = tmp4;
199121
+ ps[13] = pi2 + 0;
199122
+ ps[14] = pi2 + 1;
199123
+ ps[15] = pi2 + 2;
199124
+ ps[8] = tmp3;
199125
+ ps[9] = pi2 + 9;
199126
+ ps[10] = pi2 + 10;
199127
+ ps[11] = pi2 + 3;
199128
+ ps[4] = tmp2;
199129
+ ps[5] = pi2 + 8;
199130
+ ps[6] = pi2 + 11;
199131
+ ps[7] = pi2 + 4;
199132
+ ps[0] = tmp1;
199133
+ ps[1] = pi2 + 7;
199134
+ ps[2] = pi2 + 6;
199135
+ ps[3] = pi2 + 5;
199136
+ tmp1 = cs[2];
199137
+ tmp2 = cs[3];
199138
+ cs[2] = tmp2;
199139
+ cs[3] = ci;
199140
+ cs[0] = tmp1;
199141
+ cs[1] = ci + 1;
199142
+ break;
199143
+ // prettier-ignore
199144
+ case 2:
199145
+ tmp1 = ps[15];
199146
+ tmp2 = ps[11];
199147
+ ps[12] = ps[3];
199148
+ ps[13] = pi2 + 0;
199149
+ ps[14] = pi2 + 1;
199150
+ ps[15] = pi2 + 2;
199151
+ ps[8] = ps[7];
199152
+ ps[9] = pi2 + 9;
199153
+ ps[10] = pi2 + 10;
199154
+ ps[11] = pi2 + 3;
199155
+ ps[4] = tmp2;
199156
+ ps[5] = pi2 + 8;
199157
+ ps[6] = pi2 + 11;
199158
+ ps[7] = pi2 + 4;
199159
+ ps[0] = tmp1;
199160
+ ps[1] = pi2 + 7;
199161
+ ps[2] = pi2 + 6;
199162
+ ps[3] = pi2 + 5;
199163
+ tmp1 = cs[3];
199164
+ cs[2] = cs[1];
199165
+ cs[3] = ci;
199166
+ cs[0] = tmp1;
199167
+ cs[1] = ci + 1;
199168
+ break;
199169
+ // prettier-ignore
199170
+ case 3:
199171
+ ps[12] = ps[0];
199172
+ ps[13] = pi2 + 0;
199173
+ ps[14] = pi2 + 1;
199174
+ ps[15] = pi2 + 2;
199175
+ ps[8] = ps[1];
199176
+ ps[9] = pi2 + 9;
199177
+ ps[10] = pi2 + 10;
199178
+ ps[11] = pi2 + 3;
199179
+ ps[4] = ps[2];
199180
+ ps[5] = pi2 + 8;
199181
+ ps[6] = pi2 + 11;
199182
+ ps[7] = pi2 + 4;
199183
+ ps[0] = ps[3];
199184
+ ps[1] = pi2 + 7;
199185
+ ps[2] = pi2 + 6;
199186
+ ps[3] = pi2 + 5;
199187
+ cs[2] = cs[0];
199188
+ cs[3] = ci;
199189
+ cs[0] = cs[1];
199190
+ cs[1] = ci + 1;
199191
+ break;
199192
+ }
199193
+ this.figures.push({
199194
+ type: MeshFigureType.PATCH,
199195
+ coords: new Int32Array(ps),
199196
+ // making copies of ps and cs
199197
+ colors: new Int32Array(cs)
199198
+ });
199199
+ }
199200
+ }
199201
+ _buildFigureFromPatch(index2) {
199202
+ const figure = this.figures[index2];
199203
+ assert2(
199204
+ figure.type === MeshFigureType.PATCH,
199205
+ "Unexpected patch mesh figure"
199206
+ );
199207
+ const coords = this.coords, colors2 = this.colors;
199208
+ const pi2 = figure.coords;
199209
+ const ci = figure.colors;
199210
+ const figureMinX = Math.min(
199211
+ coords[pi2[0]][0],
199212
+ coords[pi2[3]][0],
199213
+ coords[pi2[12]][0],
199214
+ coords[pi2[15]][0]
199215
+ );
199216
+ const figureMinY = Math.min(
199217
+ coords[pi2[0]][1],
199218
+ coords[pi2[3]][1],
199219
+ coords[pi2[12]][1],
199220
+ coords[pi2[15]][1]
199221
+ );
199222
+ const figureMaxX = Math.max(
199223
+ coords[pi2[0]][0],
199224
+ coords[pi2[3]][0],
199225
+ coords[pi2[12]][0],
199226
+ coords[pi2[15]][0]
199227
+ );
199228
+ const figureMaxY = Math.max(
199229
+ coords[pi2[0]][1],
199230
+ coords[pi2[3]][1],
199231
+ coords[pi2[12]][1],
199232
+ coords[pi2[15]][1]
199233
+ );
199234
+ let splitXBy = Math.ceil(
199235
+ (figureMaxX - figureMinX) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0])
199236
+ );
199237
+ splitXBy = MathClamp(
199238
+ splitXBy,
199239
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
199240
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
199241
+ );
199242
+ let splitYBy = Math.ceil(
199243
+ (figureMaxY - figureMinY) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1])
199244
+ );
199245
+ splitYBy = MathClamp(
199246
+ splitYBy,
199247
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
199248
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
199249
+ );
199250
+ const verticesPerRow = splitXBy + 1;
199251
+ const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
199252
+ const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
199253
+ let k = 0;
199254
+ const cl = new Uint8Array(3), cr = new Uint8Array(3);
199255
+ const c0 = colors2[ci[0]], c1 = colors2[ci[1]], c22 = colors2[ci[2]], c32 = colors2[ci[3]];
199256
+ const bRow = getB(splitYBy), bCol = getB(splitXBy);
199257
+ for (let row = 0; row <= splitYBy; row++) {
199258
+ cl[0] = (c0[0] * (splitYBy - row) + c22[0] * row) / splitYBy | 0;
199259
+ cl[1] = (c0[1] * (splitYBy - row) + c22[1] * row) / splitYBy | 0;
199260
+ cl[2] = (c0[2] * (splitYBy - row) + c22[2] * row) / splitYBy | 0;
199261
+ cr[0] = (c1[0] * (splitYBy - row) + c32[0] * row) / splitYBy | 0;
199262
+ cr[1] = (c1[1] * (splitYBy - row) + c32[1] * row) / splitYBy | 0;
199263
+ cr[2] = (c1[2] * (splitYBy - row) + c32[2] * row) / splitYBy | 0;
199264
+ for (let col = 0; col <= splitXBy; col++, k++) {
199265
+ if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
199266
+ continue;
199267
+ }
199268
+ let x = 0, y = 0;
199269
+ let q2 = 0;
199270
+ for (let i = 0; i <= 3; i++) {
199271
+ for (let j = 0; j <= 3; j++, q2++) {
199272
+ const m = bRow[row][i] * bCol[col][j];
199273
+ x += coords[pi2[q2]][0] * m;
199274
+ y += coords[pi2[q2]][1] * m;
199275
+ }
199276
+ }
199277
+ figureCoords[k] = coords.length;
199278
+ coords.push([x, y]);
199279
+ figureColors[k] = colors2.length;
199280
+ const newColor = new Uint8Array(3);
199281
+ newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
199282
+ newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
199283
+ newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
199284
+ colors2.push(newColor);
199285
+ }
199286
+ }
199287
+ figureCoords[0] = pi2[0];
199288
+ figureColors[0] = ci[0];
199289
+ figureCoords[splitXBy] = pi2[3];
199290
+ figureColors[splitXBy] = ci[1];
199291
+ figureCoords[verticesPerRow * splitYBy] = pi2[12];
199292
+ figureColors[verticesPerRow * splitYBy] = ci[2];
199293
+ figureCoords[verticesPerRow * splitYBy + splitXBy] = pi2[15];
199294
+ figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
199295
+ this.figures[index2] = {
199296
+ type: MeshFigureType.LATTICE,
199297
+ coords: figureCoords,
199298
+ colors: figureColors,
199299
+ verticesPerRow
199300
+ };
199301
+ }
199302
+ _updateBounds() {
199303
+ meshUpdateBounds(this);
199304
+ }
199305
+ _packData() {
199306
+ meshPackData(this);
199307
+ }
199308
+ getIR() {
199309
+ const { posData, colData, vertexCount } = buildMeshVertexData(
199310
+ this.coords,
199311
+ this.colors,
199312
+ this.figures
199313
+ );
199314
+ return [
199315
+ "Mesh",
199316
+ this.shadingType,
199317
+ posData,
199318
+ colData,
199319
+ vertexCount,
199320
+ this.bounds,
199321
+ this.bbox,
199322
+ this.background
199323
+ ];
199324
+ }
199325
+ };
198627
199326
  var PdfError2 = class extends Error {
198628
199327
  constructor(code, message) {
198629
199328
  super(message);
@@ -201529,11 +202228,16 @@ function parseDictionaryStream(dictNode, lexer, bytes) {
201529
202228
  let streamEnd = streamStart;
201530
202229
  if (resolvedLength !== void 0 && resolvedLength >= 0 && streamStart + resolvedLength <= bytes.length) {
201531
202230
  const candidateEnd = streamStart + resolvedLength;
201532
- const tailSlice = bytes.subarray(candidateEnd, Math.min(bytes.length, candidateEnd + 32));
201533
- const tailStr = new TextDecoder("latin1").decode(tailSlice);
201534
- if (tailStr.includes("endstream")) {
202231
+ const tailLexer = new CosByteLexer(bytes, candidateEnd);
202232
+ let endToken;
202233
+ try {
202234
+ endToken = tailLexer.nextToken();
202235
+ } catch (error2) {
202236
+ if (!(error2 instanceof PdfError2) || error2.code !== "E_PARSE") throw error2;
202237
+ }
202238
+ if (endToken?.kind === "keyword" && endToken.value === "endstream") {
201535
202239
  rawStreamBytes = bytes.subarray(streamStart, candidateEnd);
201536
- streamEnd = candidateEnd + tailStr.indexOf("endstream") + "endstream".length;
202240
+ streamEnd = tailLexer.offset;
201537
202241
  }
201538
202242
  }
201539
202243
  if (!rawStreamBytes) {
@@ -210901,143 +211605,28 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
210901
211605
  const r = doc.resolve(it);
210902
211606
  return r?.kind === "number" ? r.value : 0;
210903
211607
  });
210904
- const xmin = decodeNums[0], xmax = decodeNums[1], ymin = decodeNums[2], ymax = decodeNums[3];
210905
- const numColorParams = Math.max(1, Math.floor((decodeNums.length - 4) / 2));
210906
211608
  const fnNode = dictGet(shDict, "Function");
210907
211609
  const csNode = doc.resolve(dictGet(shDict, "ColorSpace"));
210908
211610
  const csName = csNode?.kind === "name" ? csNode.decoded : "DeviceRGB";
210909
- let bitPos = 0;
210910
- const totalBits = bytes.length * 8;
210911
- const readBits = (n) => {
210912
- let val = 0;
210913
- for (let i = 0; i < n; i++) {
210914
- if (bitPos >= totalBits) return val;
210915
- const byteIdx = bitPos >> 3;
210916
- const bitIdx = 7 - (bitPos & 7);
210917
- val = val * 2 + (bytes[byteIdx] >> bitIdx & 1);
210918
- bitPos++;
210919
- }
210920
- return val;
210921
- };
210922
- const coordMax = Math.pow(2, bpcCoord) - 1 || 1;
210923
- const compMax = Math.pow(2, bpcComp) - 1 || 1;
210924
- const readCoord = () => {
210925
- const rx = readBits(bpcCoord) / coordMax;
210926
- const ry = readBits(bpcCoord) / coordMax;
210927
- return [xmin + rx * (xmax - xmin), ymin + ry * (ymax - ymin)];
210928
- };
210929
- const readColorRgb = () => {
210930
- const params = [];
210931
- for (let c4 = 0; c4 < numColorParams; c4++) {
210932
- const rc = readBits(bpcComp) / compMax;
210933
- const cMin = decodeNums[4 + c4 * 2] ?? 0;
210934
- const cMax = decodeNums[4 + c4 * 2 + 1] ?? 1;
210935
- params.push(cMin + rc * (cMax - cMin));
210936
- }
210937
- const comps = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
210938
- return convertColorSpaceComponentsToRgb(doc, csNode, csName, comps);
210939
- };
210940
- const triangles = [];
210941
- if (shType === 4) {
210942
- const minBitsPerVert = bpcFlag + 2 * bpcCoord + numColorParams * bpcComp;
210943
- let triVerts;
210944
- while (bitPos + minBitsPerVert <= totalBits) {
210945
- const flag = readBits(bpcFlag) & 3;
210946
- const [x, y] = readCoord();
210947
- const rgb22 = readColorRgb();
210948
- const vNew = { x, y, rgb: rgb22 };
210949
- if (flag === 0 || !triVerts) {
210950
- if (bitPos + 2 * minBitsPerVert > totalBits) break;
210951
- readBits(bpcFlag);
210952
- const [x1, y1] = readCoord();
210953
- const rgb1 = readColorRgb();
210954
- readBits(bpcFlag);
210955
- const [x2, y2] = readCoord();
210956
- const rgb222 = readColorRgb();
210957
- triVerts = [vNew, { x: x1, y: y1, rgb: rgb1 }, { x: x2, y: y2, rgb: rgb222 }];
210958
- triangles.push(triVerts);
210959
- } else if (flag === 1) {
210960
- triVerts = [triVerts[1], triVerts[2], vNew];
210961
- triangles.push(triVerts);
210962
- } else if (flag === 2) {
210963
- triVerts = [triVerts[0], triVerts[2], vNew];
210964
- triangles.push(triVerts);
210965
- }
210966
- }
210967
- } else if (shType === 5) {
210968
- const minBitsPerVert = 2 * bpcCoord + numColorParams * bpcComp;
210969
- const verts = [];
210970
- while (bitPos + minBitsPerVert <= totalBits) {
210971
- const [x, y] = readCoord();
210972
- const rgb22 = readColorRgb();
210973
- verts.push({ x, y, rgb: rgb22 });
210974
- }
210975
- const numRows = Math.floor(verts.length / vPerRow);
210976
- for (let r = 0; r + 1 < numRows; r++) {
210977
- for (let c4 = 0; c4 + 1 < vPerRow; c4++) {
210978
- const v00 = verts[r * vPerRow + c4];
210979
- const v01 = verts[r * vPerRow + c4 + 1];
210980
- const v11 = verts[(r + 1) * vPerRow + c4 + 1];
210981
- const v10 = verts[(r + 1) * vPerRow + c4];
210982
- triangles.push([v00, v01, v11], [v00, v11, v10]);
210983
- }
210984
- }
210985
- } else if (shType === 6 || shType === 7) {
210986
- const numCtrl = shType === 6 ? 12 : 16;
210987
- const minBitsPatch = bpcFlag + (numCtrl - 4) * 2 * bpcCoord + 2 * numColorParams * bpcComp;
210988
- let prevPts;
210989
- let prevColors;
210990
- while (bitPos + minBitsPatch <= totalBits) {
210991
- const flag = readBits(bpcFlag) & 3;
210992
- let pts = [];
210993
- let cols = [];
210994
- if (flag === 0 || !prevPts || !prevColors) {
210995
- for (let i = 0; i < numCtrl; i++) pts.push(readCoord());
210996
- for (let i = 0; i < 4; i++) cols.push(readColorRgb());
210997
- } else {
210998
- const extraCtrl = numCtrl - 4;
210999
- const readExtra = [];
211000
- for (let i = 0; i < extraCtrl; i++) readExtra.push(readCoord());
211001
- const c22 = readColorRgb();
211002
- const c32 = readColorRgb();
211003
- pts = [prevPts[3], prevPts[4], prevPts[5], prevPts[6], ...readExtra];
211004
- cols = [prevColors[1], prevColors[2], c22, c32];
211005
- }
211006
- prevPts = pts;
211007
- prevColors = cols;
211008
- const p00 = pts[0];
211009
- const p03 = pts[3];
211010
- const p33 = pts[6];
211011
- const p30 = pts[9];
211012
- const c00 = cols[0], c03 = cols[1], c33 = cols[2], c30 = cols[3];
211013
- const steps = 4;
211014
- const grid = [];
211015
- for (let iu = 0; iu <= steps; iu++) {
211016
- const u = iu / steps;
211017
- const row = [];
211018
- for (let iv = 0; iv <= steps; iv++) {
211019
- const v = iv / steps;
211020
- const x = (1 - u) * (1 - v) * p00[0] + (1 - u) * v * p03[0] + u * v * p33[0] + u * (1 - v) * p30[0];
211021
- const y = (1 - u) * (1 - v) * p00[1] + (1 - u) * v * p03[1] + u * v * p33[1] + u * (1 - v) * p30[1];
211022
- const r = (1 - u) * (1 - v) * c00[0] + (1 - u) * v * c03[0] + u * v * c33[0] + u * (1 - v) * c30[0];
211023
- const g = (1 - u) * (1 - v) * c00[1] + (1 - u) * v * c03[1] + u * v * c33[1] + u * (1 - v) * c30[1];
211024
- const b3 = (1 - u) * (1 - v) * c00[2] + (1 - u) * v * c03[2] + u * v * c33[2] + u * (1 - v) * c30[2];
211025
- row.push({ x, y, rgb: [r, g, b3] });
211026
- }
211027
- grid.push(row);
211028
- }
211029
- for (let iu = 0; iu < steps; iu++) {
211030
- for (let iv = 0; iv < steps; iv++) {
211031
- const g00 = grid[iu][iv];
211032
- const g01 = grid[iu][iv + 1];
211033
- const g11 = grid[iu + 1][iv + 1];
211034
- const g10 = grid[iu + 1][iv];
211035
- triangles.push([g00, g01, g11], [g00, g11, g10]);
211036
- }
211037
- }
211038
- }
211039
- }
211040
- if (triangles.length === 0) return void 0;
211611
+ const numComps = fnNode ? 1 : getColorSpaceComponentCount(doc, csNode);
211612
+ const mesh = new MeshShading(shType, new Stream(bytes), {
211613
+ bitsPerCoordinate: bpcCoord,
211614
+ bitsPerComponent: bpcComp,
211615
+ bitsPerFlag: bpcFlag,
211616
+ decode: decodeNums,
211617
+ numComps,
211618
+ colorFn: null,
211619
+ colorSpace: {
211620
+ numComps,
211621
+ getRgb(components22) {
211622
+ const params = Array.from(components22);
211623
+ const values2 = fnNode ? evalShadingFunctionToComponents(doc, fnNode, params) : params;
211624
+ return new Uint8Array(convertColorSpaceComponentsToRgb(doc, csNode, csName, values2).map((value3) => Math.round(Math.max(0, Math.min(1, value3)) * 255)));
211625
+ }
211626
+ }
211627
+ }, vPerRow);
211628
+ const [, , positions, colors2, vertexCount] = mesh.getIR();
211629
+ if (vertexCount === 0) return void 0;
211041
211630
  const [bx0, by0, bx1, by1] = targetBox;
211042
211631
  const boxW = Math.max(1, bx1 - bx0);
211043
211632
  const boxH = Math.max(1, by1 - by0);
@@ -211049,10 +211638,10 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
211049
211638
  const [px, py] = transformPoint(effectiveCtm, vx, vy);
211050
211639
  return [(px - bx0) / boxW * imgW, (by1 - py) / boxH * imgH];
211051
211640
  };
211052
- for (const [v0, v1, v2] of triangles) {
211053
- const [x0, y0] = toImgCoords(v0.x, v0.y);
211054
- const [x1, y1] = toImgCoords(v1.x, v1.y);
211055
- const [x2, y2] = toImgCoords(v2.x, v2.y);
211641
+ for (let vertex = 0; vertex < vertexCount; vertex += 3) {
211642
+ const [x0, y0] = toImgCoords(positions[vertex * 2], positions[vertex * 2 + 1]);
211643
+ const [x1, y1] = toImgCoords(positions[vertex * 2 + 2], positions[vertex * 2 + 3]);
211644
+ const [x2, y2] = toImgCoords(positions[vertex * 2 + 4], positions[vertex * 2 + 5]);
211056
211645
  const denom = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2);
211057
211646
  if (Math.abs(denom) < 1e-6) continue;
211058
211647
  const minX = Math.max(0, Math.floor(Math.min(x0, x1, x2)));
@@ -211067,13 +211656,12 @@ function renderMeshShadingToImage(doc, shDict, shStream, shType, effectiveCtm, t
211067
211656
  const w1 = ((y2 - y0) * (px - x2) + (x0 - x2) * (py - y2)) / denom;
211068
211657
  const w2 = 1 - w0 - w1;
211069
211658
  if (w0 >= -1e-4 && w1 >= -1e-4 && w2 >= -1e-4) {
211070
- const r = w0 * v0.rgb[0] + w1 * v1.rgb[0] + w2 * v2.rgb[0];
211071
- const g = w0 * v0.rgb[1] + w1 * v1.rgb[1] + w2 * v2.rgb[1];
211072
- const b3 = w0 * v0.rgb[2] + w1 * v1.rgb[2] + w2 * v2.rgb[2];
211073
211659
  const pIdx = (iy * imgW + ix) * 4;
211074
- rgba[pIdx] = Math.round(Math.max(0, Math.min(1, r)) * 255);
211075
- rgba[pIdx + 1] = Math.round(Math.max(0, Math.min(1, g)) * 255);
211076
- rgba[pIdx + 2] = Math.round(Math.max(0, Math.min(1, b3)) * 255);
211660
+ for (let channel = 0; channel < 3; channel++) {
211661
+ rgba[pIdx + channel] = Math.round(
211662
+ w0 * colors2[vertex * 4 + channel] + w1 * colors2[vertex * 4 + 4 + channel] + w2 * colors2[vertex * 4 + 8 + channel]
211663
+ );
211664
+ }
211077
211665
  rgba[pIdx + 3] = a8;
211078
211666
  }
211079
211667
  }
@@ -211160,6 +211748,8 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
211160
211748
  const [a3, b3, c4, d2, e, f2] = effectiveCtm;
211161
211749
  const det = a3 * d2 - b3 * c4;
211162
211750
  if (Math.abs(det) <= 1e-8) return void 0;
211751
+ const [sa, sb, sc, sd, se, sf] = shadingCtm;
211752
+ const shadingDet = sa * sd - sb * sc;
211163
211753
  const t0Dom = shDomain[0] ?? 0;
211164
211754
  const t1Dom = shDomain[1] ?? 1;
211165
211755
  for (let iy = 0; iy < imgH; iy++) {
@@ -211170,8 +211760,10 @@ function renderShadingDictToImage(doc, shDict, shadingCtm, targetBox, fillAlpha,
211170
211760
  const dxPdf = xPdf - e;
211171
211761
  const xs = (d2 * dxPdf - c4 * dyPdf) / det;
211172
211762
  const ys = (-b3 * dxPdf + a3 * dyPdf) / det;
211173
- if (shBBox && (xs < shBBox[0] || xs > shBBox[2] || ys < shBBox[1] || ys > shBBox[3])) {
211174
- continue;
211763
+ if (shBBox) {
211764
+ const bboxX = (sd * (xPdf - se) - sc * (yPdf - sf)) / shadingDet;
211765
+ const bboxY = (-sb * (xPdf - se) + sa * (yPdf - sf)) / shadingDet;
211766
+ if (bboxX < shBBox[0] || bboxX > shBBox[2] || bboxY < shBBox[1] || bboxY > shBBox[3]) continue;
211175
211767
  }
211176
211768
  let comps;
211177
211769
  if (shType === 1) {