@poe-platform/safe-bash 0.1.761 → 0.1.762

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 (28) hide show
  1. package/dist/image-ast/index.browser.js +69 -7
  2. package/dist/image-ast/index.js +69 -7
  3. package/dist/pdf-ast/index.js +71 -7
  4. package/dist/safe-bash/command-chunks/{chunk-6VX5ZQL5.js → chunk-D4GXXV65.js} +2 -2
  5. package/dist/safe-bash/command-chunks/{chunk-GR725WRX.js → chunk-F7MJRXQ2.js} +1 -1
  6. package/dist/safe-bash/command-chunks/{chunk-OSMLVM7P.js → chunk-P3Q2QSCA.js} +72 -7
  7. package/dist/safe-bash/commands/csvcut/index.d.ts +1 -1
  8. package/dist/safe-bash/commands/csvcut/index.js +3 -1
  9. package/dist/safe-bash/commands/csvgrep/index.d.ts +1 -1
  10. package/dist/safe-bash/commands/csvgrep/index.js +3 -1
  11. package/dist/safe-bash/core.browser.js +7 -5
  12. package/dist/safe-bash/shell/runtime.js +4 -4
  13. package/dist/safe-bash-command-ffmpeg/index.js +1423 -1388
  14. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  15. package/dist/safe-bash-command-pandoc/command.js +3 -3
  16. package/dist/safe-bash-command-pandoc/index.js +3 -3
  17. package/dist/safe-bash-command-pdfimages/index.js +69 -7
  18. package/dist/safe-bash-command-pdfinfo/index.js +69 -7
  19. package/dist/safe-bash-command-pdftk/index.js +69 -7
  20. package/dist/safe-bash-command-pdftoppm/index.js +69 -7
  21. package/dist/safe-bash-command-pdftotext/index.js +69 -7
  22. package/dist/safe-bash-command-qpdf/index.js +69 -7
  23. package/dist/safe-bash-command-sips/index.js +2 -2
  24. package/dist/safe-bash-command-soffice/index.js +1 -1
  25. package/dist/safe-bash-command-ssconvert/index.js +69 -7
  26. package/dist/safe-bash-command-wkhtmltopdf/index.js +69 -7
  27. package/package.json +2 -2
  28. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +10 -0
@@ -46707,6 +46707,47 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
46707
46707
  points.push([x4, y4]);
46708
46708
  return points;
46709
46709
  }
46710
+ function sampleImageLinear(image, x, y, out) {
46711
+ x = Math.max(0, Math.min(image.width - 1, x));
46712
+ y = Math.max(0, Math.min(image.height - 1, y));
46713
+ const x0 = Math.floor(x), y0 = Math.floor(y);
46714
+ const fx = x - x0, fy = y - y0;
46715
+ out.fill(0);
46716
+ for (let j = 0; j < 2; j++) {
46717
+ for (let i = 0; i < 2; i++) {
46718
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
46719
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
46720
+ out[0] = out[0] + image.data[offset] * alpha;
46721
+ out[1] = out[1] + image.data[offset + 1] * alpha;
46722
+ out[2] = out[2] + image.data[offset + 2] * alpha;
46723
+ out[3] = out[3] + alpha;
46724
+ }
46725
+ }
46726
+ if (out[3] > 0) {
46727
+ out[0] = out[0] / out[3];
46728
+ out[1] = out[1] / out[3];
46729
+ out[2] = out[2] / out[3];
46730
+ }
46731
+ }
46732
+ function downscaleImage(image, widthScale, heightScale) {
46733
+ const sample = new Float64Array(4);
46734
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
46735
+ const width = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
46736
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
46737
+ const data = new Uint8Array(width * height * 4);
46738
+ for (let y = 0; y < height; y++) {
46739
+ for (let x = 0; x < width; x++) {
46740
+ sampleImageLinear(image, (x + 0.5) * image.width / width - 0.5, (y + 0.5) * image.height / height - 0.5, sample);
46741
+ const offset = (y * width + x) * 4;
46742
+ for (let c = 0; c < 4; c++) data[offset + c] = Math.round(sample[c]);
46743
+ }
46744
+ }
46745
+ widthScale /= image.width / width;
46746
+ heightScale /= image.height / height;
46747
+ image = { width, height, data };
46748
+ }
46749
+ return image;
46750
+ }
46710
46751
  function decodePng(pngBytes) {
46711
46752
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
46712
46753
  throw new Error("Invalid PNG signature");
@@ -47759,6 +47800,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
47759
47800
  const maxPx = Math.min(width - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
47760
47801
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
47761
47802
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
47803
+ if (minPx > maxPx || minPy > maxPy) continue;
47804
+ const source = downscaleImage(
47805
+ { width: img.width, height: img.height, data: img.decodedRgba },
47806
+ Math.hypot(d, c) * img.width / Math.abs(det * scale),
47807
+ Math.hypot(b, a) * img.height / Math.abs(det * scale)
47808
+ );
47809
+ const ax = a * scale / img.width, ay = b * scale / img.width;
47810
+ const bx = c * scale / img.height, by = d * scale / img.height;
47811
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
47812
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
47813
+ const sample = new Float64Array(4);
47762
47814
  for (let py = minPy; py <= maxPy; py++) {
47763
47815
  const yPdf = displayList.height - (py + 0.5) / scale;
47764
47816
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -47770,9 +47822,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
47770
47822
  const u = (d * dxPdf - c * dyPdf) / det;
47771
47823
  const v = (-b * dxPdf + a * dyPdf) / det;
47772
47824
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
47773
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
47774
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
47775
- const sIdx = (sy * img.width + sx) * 4;
47825
+ if (smooth) {
47826
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample);
47827
+ } else {
47828
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
47829
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
47830
+ const sIdx = (sy * source.width + sx) * 4;
47831
+ for (let c2 = 0; c2 < 4; c2++) sample[c2] = source.data[sIdx + c2];
47832
+ }
47776
47833
  blendPixel(
47777
47834
  rgba,
47778
47835
  width,
@@ -47780,11 +47837,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
47780
47837
  px,
47781
47838
  py,
47782
47839
  {
47783
- r: img.decodedRgba[sIdx] / 255,
47784
- g: img.decodedRgba[sIdx + 1] / 255,
47785
- b: img.decodedRgba[sIdx + 2] / 255
47840
+ r: sample[0] / 255,
47841
+ g: sample[1] / 255,
47842
+ b: sample[2] / 255
47786
47843
  },
47787
- img.decodedRgba[sIdx + 3] / 255,
47844
+ sample[3] / 255,
47788
47845
  img.blendMode,
47789
47846
  clipMask
47790
47847
  );
@@ -62508,3 +62565,8 @@ export {
62508
62565
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
62509
62566
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
62510
62567
  */
62568
+ /*!
62569
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
62570
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
62571
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
62572
+ */
@@ -46707,6 +46707,47 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
46707
46707
  points.push([x4, y4]);
46708
46708
  return points;
46709
46709
  }
46710
+ function sampleImageLinear(image, x, y, out) {
46711
+ x = Math.max(0, Math.min(image.width - 1, x));
46712
+ y = Math.max(0, Math.min(image.height - 1, y));
46713
+ const x0 = Math.floor(x), y0 = Math.floor(y);
46714
+ const fx = x - x0, fy = y - y0;
46715
+ out.fill(0);
46716
+ for (let j = 0; j < 2; j++) {
46717
+ for (let i = 0; i < 2; i++) {
46718
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
46719
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
46720
+ out[0] = out[0] + image.data[offset] * alpha;
46721
+ out[1] = out[1] + image.data[offset + 1] * alpha;
46722
+ out[2] = out[2] + image.data[offset + 2] * alpha;
46723
+ out[3] = out[3] + alpha;
46724
+ }
46725
+ }
46726
+ if (out[3] > 0) {
46727
+ out[0] = out[0] / out[3];
46728
+ out[1] = out[1] / out[3];
46729
+ out[2] = out[2] / out[3];
46730
+ }
46731
+ }
46732
+ function downscaleImage(image, widthScale, heightScale) {
46733
+ const sample = new Float64Array(4);
46734
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
46735
+ const width = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
46736
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
46737
+ const data = new Uint8Array(width * height * 4);
46738
+ for (let y = 0; y < height; y++) {
46739
+ for (let x = 0; x < width; x++) {
46740
+ sampleImageLinear(image, (x + 0.5) * image.width / width - 0.5, (y + 0.5) * image.height / height - 0.5, sample);
46741
+ const offset = (y * width + x) * 4;
46742
+ for (let c = 0; c < 4; c++) data[offset + c] = Math.round(sample[c]);
46743
+ }
46744
+ }
46745
+ widthScale /= image.width / width;
46746
+ heightScale /= image.height / height;
46747
+ image = { width, height, data };
46748
+ }
46749
+ return image;
46750
+ }
46710
46751
  function decodePng(pngBytes) {
46711
46752
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
46712
46753
  throw new Error("Invalid PNG signature");
@@ -47759,6 +47800,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
47759
47800
  const maxPx = Math.min(width - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
47760
47801
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
47761
47802
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
47803
+ if (minPx > maxPx || minPy > maxPy) continue;
47804
+ const source = downscaleImage(
47805
+ { width: img.width, height: img.height, data: img.decodedRgba },
47806
+ Math.hypot(d, c) * img.width / Math.abs(det * scale),
47807
+ Math.hypot(b, a) * img.height / Math.abs(det * scale)
47808
+ );
47809
+ const ax = a * scale / img.width, ay = b * scale / img.width;
47810
+ const bx = c * scale / img.height, by = d * scale / img.height;
47811
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
47812
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
47813
+ const sample = new Float64Array(4);
47762
47814
  for (let py = minPy; py <= maxPy; py++) {
47763
47815
  const yPdf = displayList.height - (py + 0.5) / scale;
47764
47816
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -47770,9 +47822,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
47770
47822
  const u = (d * dxPdf - c * dyPdf) / det;
47771
47823
  const v = (-b * dxPdf + a * dyPdf) / det;
47772
47824
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
47773
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
47774
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
47775
- const sIdx = (sy * img.width + sx) * 4;
47825
+ if (smooth) {
47826
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample);
47827
+ } else {
47828
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
47829
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
47830
+ const sIdx = (sy * source.width + sx) * 4;
47831
+ for (let c2 = 0; c2 < 4; c2++) sample[c2] = source.data[sIdx + c2];
47832
+ }
47776
47833
  blendPixel(
47777
47834
  rgba,
47778
47835
  width,
@@ -47780,11 +47837,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
47780
47837
  px,
47781
47838
  py,
47782
47839
  {
47783
- r: img.decodedRgba[sIdx] / 255,
47784
- g: img.decodedRgba[sIdx + 1] / 255,
47785
- b: img.decodedRgba[sIdx + 2] / 255
47840
+ r: sample[0] / 255,
47841
+ g: sample[1] / 255,
47842
+ b: sample[2] / 255
47786
47843
  },
47787
- img.decodedRgba[sIdx + 3] / 255,
47844
+ sample[3] / 255,
47788
47845
  img.blendMode,
47789
47846
  clipMask
47790
47847
  );
@@ -62508,3 +62565,8 @@ export {
62508
62565
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
62509
62566
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
62510
62567
  */
62568
+ /*!
62569
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
62570
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
62571
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
62572
+ */
@@ -40113,6 +40113,49 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
40113
40113
  return points;
40114
40114
  }
40115
40115
 
40116
+ // src/render/image-sampling.ts
40117
+ function sampleImageLinear(image, x, y, out) {
40118
+ x = Math.max(0, Math.min(image.width - 1, x));
40119
+ y = Math.max(0, Math.min(image.height - 1, y));
40120
+ const x0 = Math.floor(x), y0 = Math.floor(y);
40121
+ const fx = x - x0, fy = y - y0;
40122
+ out.fill(0);
40123
+ for (let j = 0; j < 2; j++) {
40124
+ for (let i = 0; i < 2; i++) {
40125
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
40126
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
40127
+ out[0] = out[0] + image.data[offset] * alpha;
40128
+ out[1] = out[1] + image.data[offset + 1] * alpha;
40129
+ out[2] = out[2] + image.data[offset + 2] * alpha;
40130
+ out[3] = out[3] + alpha;
40131
+ }
40132
+ }
40133
+ if (out[3] > 0) {
40134
+ out[0] = out[0] / out[3];
40135
+ out[1] = out[1] / out[3];
40136
+ out[2] = out[2] / out[3];
40137
+ }
40138
+ }
40139
+ function downscaleImage(image, widthScale, heightScale) {
40140
+ const sample = new Float64Array(4);
40141
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
40142
+ const width = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
40143
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
40144
+ const data = new Uint8Array(width * height * 4);
40145
+ for (let y = 0; y < height; y++) {
40146
+ for (let x = 0; x < width; x++) {
40147
+ sampleImageLinear(image, (x + 0.5) * image.width / width - 0.5, (y + 0.5) * image.height / height - 0.5, sample);
40148
+ const offset = (y * width + x) * 4;
40149
+ for (let c = 0; c < 4; c++) data[offset + c] = Math.round(sample[c]);
40150
+ }
40151
+ }
40152
+ widthScale /= image.width / width;
40153
+ heightScale /= image.height / height;
40154
+ image = { width, height, data };
40155
+ }
40156
+ return image;
40157
+ }
40158
+
40116
40159
  // src/render/raster.ts
40117
40160
  function encodePng(bitmap) {
40118
40161
  return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
@@ -41562,6 +41605,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
41562
41605
  const maxPx = Math.min(width - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
41563
41606
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
41564
41607
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
41608
+ if (minPx > maxPx || minPy > maxPy) continue;
41609
+ const source = downscaleImage(
41610
+ { width: img.width, height: img.height, data: img.decodedRgba },
41611
+ Math.hypot(d, c) * img.width / Math.abs(det * scale),
41612
+ Math.hypot(b, a) * img.height / Math.abs(det * scale)
41613
+ );
41614
+ const ax = a * scale / img.width, ay = b * scale / img.width;
41615
+ const bx = c * scale / img.height, by = d * scale / img.height;
41616
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
41617
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
41618
+ const sample = new Float64Array(4);
41565
41619
  for (let py = minPy; py <= maxPy; py++) {
41566
41620
  const yPdf = displayList.height - (py + 0.5) / scale;
41567
41621
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -41573,9 +41627,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
41573
41627
  const u = (d * dxPdf - c * dyPdf) / det;
41574
41628
  const v = (-b * dxPdf + a * dyPdf) / det;
41575
41629
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
41576
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
41577
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
41578
- const sIdx = (sy * img.width + sx) * 4;
41630
+ if (smooth) {
41631
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample);
41632
+ } else {
41633
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
41634
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
41635
+ const sIdx = (sy * source.width + sx) * 4;
41636
+ for (let c2 = 0; c2 < 4; c2++) sample[c2] = source.data[sIdx + c2];
41637
+ }
41579
41638
  blendPixel(
41580
41639
  rgba,
41581
41640
  width,
@@ -41583,11 +41642,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
41583
41642
  px,
41584
41643
  py,
41585
41644
  {
41586
- r: img.decodedRgba[sIdx] / 255,
41587
- g: img.decodedRgba[sIdx + 1] / 255,
41588
- b: img.decodedRgba[sIdx + 2] / 255
41645
+ r: sample[0] / 255,
41646
+ g: sample[1] / 255,
41647
+ b: sample[2] / 255
41589
41648
  },
41590
- img.decodedRgba[sIdx + 3] / 255,
41649
+ sample[3] / 255,
41591
41650
  img.blendMode,
41592
41651
  clipMask
41593
41652
  );
@@ -42682,3 +42741,8 @@ export {
42682
42741
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
42683
42742
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
42684
42743
  */
42744
+ /*!
42745
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
42746
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
42747
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
42748
+ */
@@ -48,11 +48,11 @@ import {
48
48
  trimImage,
49
49
  unflattenImage,
50
50
  unpremultiplyRgbaImage
51
- } from "./chunk-GR725WRX.js";
51
+ } from "./chunk-F7MJRXQ2.js";
52
52
  import {
53
53
  PdfDocument,
54
54
  encodePng
55
- } from "./chunk-OSMLVM7P.js";
55
+ } from "./chunk-P3Q2QSCA.js";
56
56
  import {
57
57
  createLuaFilterCapability
58
58
  } from "./chunk-Y2KHC6TZ.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PdfDocument,
3
3
  renderPdfPageToPng
4
- } from "./chunk-OSMLVM7P.js";
4
+ } from "./chunk-P3Q2QSCA.js";
5
5
  import {
6
6
  init_buffer
7
7
  } from "./chunk-HX3SHTCE.js";
@@ -34002,6 +34002,50 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
34002
34002
  return points;
34003
34003
  }
34004
34004
 
34005
+ // packages/pdf-ast/src/render/image-sampling.ts
34006
+ init_buffer();
34007
+ function sampleImageLinear(image, x, y, out) {
34008
+ x = Math.max(0, Math.min(image.width - 1, x));
34009
+ y = Math.max(0, Math.min(image.height - 1, y));
34010
+ const x0 = Math.floor(x), y0 = Math.floor(y);
34011
+ const fx = x - x0, fy = y - y0;
34012
+ out.fill(0);
34013
+ for (let j = 0; j < 2; j++) {
34014
+ for (let i = 0; i < 2; i++) {
34015
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
34016
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
34017
+ out[0] = out[0] + image.data[offset] * alpha;
34018
+ out[1] = out[1] + image.data[offset + 1] * alpha;
34019
+ out[2] = out[2] + image.data[offset + 2] * alpha;
34020
+ out[3] = out[3] + alpha;
34021
+ }
34022
+ }
34023
+ if (out[3] > 0) {
34024
+ out[0] = out[0] / out[3];
34025
+ out[1] = out[1] / out[3];
34026
+ out[2] = out[2] / out[3];
34027
+ }
34028
+ }
34029
+ function downscaleImage(image, widthScale, heightScale) {
34030
+ const sample = new Float64Array(4);
34031
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
34032
+ const width = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
34033
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
34034
+ const data = new Uint8Array(width * height * 4);
34035
+ for (let y = 0; y < height; y++) {
34036
+ for (let x = 0; x < width; x++) {
34037
+ sampleImageLinear(image, (x + 0.5) * image.width / width - 0.5, (y + 0.5) * image.height / height - 0.5, sample);
34038
+ const offset = (y * width + x) * 4;
34039
+ for (let c = 0; c < 4; c++) data[offset + c] = Math.round(sample[c]);
34040
+ }
34041
+ }
34042
+ widthScale /= image.width / width;
34043
+ heightScale /= image.height / height;
34044
+ image = { width, height, data };
34045
+ }
34046
+ return image;
34047
+ }
34048
+
34005
34049
  // packages/pdf-ast/src/render/raster.ts
34006
34050
  function encodePng(bitmap) {
34007
34051
  return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
@@ -35058,6 +35102,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
35058
35102
  const maxPx = Math.min(width - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
35059
35103
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
35060
35104
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
35105
+ if (minPx > maxPx || minPy > maxPy) continue;
35106
+ const source = downscaleImage(
35107
+ { width: img.width, height: img.height, data: img.decodedRgba },
35108
+ Math.hypot(d, c) * img.width / Math.abs(det * scale),
35109
+ Math.hypot(b, a) * img.height / Math.abs(det * scale)
35110
+ );
35111
+ const ax = a * scale / img.width, ay = b * scale / img.width;
35112
+ const bx = c * scale / img.height, by = d * scale / img.height;
35113
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
35114
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
35115
+ const sample = new Float64Array(4);
35061
35116
  for (let py = minPy; py <= maxPy; py++) {
35062
35117
  const yPdf = displayList.height - (py + 0.5) / scale;
35063
35118
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -35069,9 +35124,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
35069
35124
  const u = (d * dxPdf - c * dyPdf) / det;
35070
35125
  const v = (-b * dxPdf + a * dyPdf) / det;
35071
35126
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
35072
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
35073
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
35074
- const sIdx = (sy * img.width + sx) * 4;
35127
+ if (smooth) {
35128
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample);
35129
+ } else {
35130
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
35131
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
35132
+ const sIdx = (sy * source.width + sx) * 4;
35133
+ for (let c2 = 0; c2 < 4; c2++) sample[c2] = source.data[sIdx + c2];
35134
+ }
35075
35135
  blendPixel(
35076
35136
  rgba,
35077
35137
  width,
@@ -35079,11 +35139,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
35079
35139
  px,
35080
35140
  py,
35081
35141
  {
35082
- r: img.decodedRgba[sIdx] / 255,
35083
- g: img.decodedRgba[sIdx + 1] / 255,
35084
- b: img.decodedRgba[sIdx + 2] / 255
35142
+ r: sample[0] / 255,
35143
+ g: sample[1] / 255,
35144
+ b: sample[2] / 255
35085
35145
  },
35086
- img.decodedRgba[sIdx + 3] / 255,
35146
+ sample[3] / 255,
35087
35147
  img.blendMode,
35088
35148
  clipMask
35089
35149
  );
@@ -37278,3 +37338,8 @@ export {
37278
37338
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
37279
37339
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
37280
37340
  */
37341
+ /*!
37342
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
37343
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
37344
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
37345
+ */
@@ -5,5 +5,5 @@ export declare function createCsvcutCommand(options?: CsvcutCommandOptions): Com
5
5
  export declare const csvcutCommand: CommandDefinition;
6
6
  export declare function createCsvcutCommands(options?: CsvcutCommandsOptions): readonly CommandDefinition[];
7
7
  export declare function csvcutCommands(options?: CsvcutCommandsOptions): VirtualShellPlugin;
8
- export declare function evalSyncCsvcut(inBytes: Uint8Array, opArgs: readonly string[], readFileSync?: (filePath: string) => Uint8Array | undefined): string | undefined;
8
+ export declare function evalSyncCsvcut(inBytes: Uint8Array | undefined, opArgs: readonly string[], readFileSync?: (filePath: string) => Uint8Array | undefined): string | undefined;
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -31,7 +31,7 @@ export function csvcutCommands(options = {}) {
31
31
  let _syncAbortSignal;
32
32
  const syncAbortSignal = () => (_syncAbortSignal ??= new AbortController().signal);
33
33
  export function evalSyncCsvcut(inBytes, opArgs, readFileSync) {
34
- if (inBytes.byteLength > 16384)
34
+ if (inBytes !== undefined && inBytes.byteLength > 16384)
35
35
  return undefined;
36
36
  const budget = new CsvBudget({}, syncAbortSignal());
37
37
  try {
@@ -55,6 +55,8 @@ export function evalSyncCsvcut(inBytes, opArgs, readFileSync) {
55
55
  const dialect = { ...supplied.dialect, profile: supplied.dialect?.profile ?? "utf8-sig-permissive-v1" };
56
56
  if (Number.isSafeInteger(dialect.skipLines) && dialect.skipLines < 0)
57
57
  dialect.skipLines = 0;
58
+ if (sourceBytes === undefined)
59
+ return undefined;
58
60
  const parser = new CsvParser(dialect, budget);
59
61
  const rows = [...parser.push(sourceBytes), ...parser.end()];
60
62
  const first = rows[0];
@@ -5,5 +5,5 @@ export declare function createCsvgrepCommand(options?: CsvgrepCommandOptions): C
5
5
  export declare const csvgrepCommand: CommandDefinition;
6
6
  export declare function createCsvgrepCommands(options?: CsvgrepCommandsOptions): readonly CommandDefinition[];
7
7
  export declare function csvgrepCommands(options?: CsvgrepCommandsOptions): VirtualShellPlugin;
8
- export declare function evalSyncCsvgrep(inBytes: Uint8Array, opArgs: readonly string[], readFileSync?: (filePath: string) => Uint8Array | undefined): string | undefined;
8
+ export declare function evalSyncCsvgrep(inBytes: Uint8Array | undefined, opArgs: readonly string[], readFileSync?: (filePath: string) => Uint8Array | undefined): string | undefined;
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -31,7 +31,7 @@ export function csvgrepCommands(options = {}) {
31
31
  let _syncAbortSignal;
32
32
  const syncAbortSignal = () => (_syncAbortSignal ??= new AbortController().signal);
33
33
  export function evalSyncCsvgrep(inBytes, opArgs, readFileSync) {
34
- if (inBytes.byteLength > 16384)
34
+ if (inBytes !== undefined && inBytes.byteLength > 16384)
35
35
  return undefined;
36
36
  const budget = new CsvBudget({}, syncAbortSignal());
37
37
  try {
@@ -64,6 +64,8 @@ export function evalSyncCsvgrep(inBytes, opArgs, readFileSync) {
64
64
  return undefined;
65
65
  sourceBytes = fileBytes;
66
66
  }
67
+ if (sourceBytes === undefined)
68
+ return undefined;
67
69
  const parser = new CsvParser(options.dialect ?? {}, budget);
68
70
  const rows = [...parser.push(sourceBytes), ...parser.end()];
69
71
  const matcher = options.names ? undefined : createMatcher(options, fileMatchSet, budget);
@@ -52394,7 +52394,7 @@ function csvcutCommands(options8 = {}) {
52394
52394
  var _syncAbortSignal;
52395
52395
  var syncAbortSignal = () => _syncAbortSignal ??= new AbortController().signal;
52396
52396
  function evalSyncCsvcut(inBytes, opArgs, readFileSync) {
52397
- if (inBytes.byteLength > 16384) return void 0;
52397
+ if (inBytes !== void 0 && inBytes.byteLength > 16384) return void 0;
52398
52398
  const budget = new CsvBudget({}, syncAbortSignal());
52399
52399
  try {
52400
52400
  const supplied = parseCsvcutArguments(opArgs, budget);
@@ -52412,6 +52412,7 @@ function evalSyncCsvcut(inBytes, opArgs, readFileSync) {
52412
52412
  if (supplied.names && supplied.headerless) return void 0;
52413
52413
  const dialect = { ...supplied.dialect, profile: supplied.dialect?.profile ?? "utf8-sig-permissive-v1" };
52414
52414
  if (Number.isSafeInteger(dialect.skipLines) && dialect.skipLines < 0) dialect.skipLines = 0;
52415
+ if (sourceBytes === void 0) return void 0;
52415
52416
  const parser = new CsvParser(dialect, budget);
52416
52417
  const rows = [...parser.push(sourceBytes), ...parser.end()];
52417
52418
  const first = rows[0];
@@ -52503,7 +52504,7 @@ function csvgrepCommands(options8 = {}) {
52503
52504
  var _syncAbortSignal2;
52504
52505
  var syncAbortSignal2 = () => _syncAbortSignal2 ??= new AbortController().signal;
52505
52506
  function evalSyncCsvgrep(inBytes, opArgs, readFileSync) {
52506
- if (inBytes.byteLength > 16384) return void 0;
52507
+ if (inBytes !== void 0 && inBytes.byteLength > 16384) return void 0;
52507
52508
  const budget = new CsvBudget2({}, syncAbortSignal2());
52508
52509
  try {
52509
52510
  const options8 = parseCsvgrepArguments(opArgs, budget);
@@ -52528,6 +52529,7 @@ function evalSyncCsvgrep(inBytes, opArgs, readFileSync) {
52528
52529
  if (!fileBytes || fileBytes.byteLength > 16384) return void 0;
52529
52530
  sourceBytes = fileBytes;
52530
52531
  }
52532
+ if (sourceBytes === void 0) return void 0;
52531
52533
  const parser = new CsvParser2(options8.dialect ?? {}, budget);
52532
52534
  const rows = [...parser.push(sourceBytes), ...parser.end()];
52533
52535
  const matcher = options8.names ? void 0 : createMatcher(options8, fileMatchSet, budget);
@@ -87414,9 +87416,9 @@ unsigned int ${ident}_len = ${view.byteLength};
87414
87416
  "LC_MEASUREMENT",
87415
87417
  "LC_IDENTIFICATION"
87416
87418
  ]) {
87417
- if (lcAll) lines4.push(`${cat}=${lcAll}`);
87419
+ if (lcAll) lines4.push(`${cat}="${lcAll}"`);
87418
87420
  else if (getEnv(cat)) lines4.push(`${cat}=${getEnv(cat)}`);
87419
- else lines4.push(`${cat}="${lang}"`);
87421
+ else lines4.push(`${cat}="${lang || "C.UTF-8"}"`);
87420
87422
  }
87421
87423
  lines4.push(`LC_ALL=${lcAll ?? ""}`);
87422
87424
  return lines4.join("\n");
@@ -89972,7 +89974,7 @@ unsigned int ${ident}_len = ${view.byteLength};
89972
89974
  const inBytes = hasSingleHereStringRedir ? fastSharedTextEncoder.encode(hereStrVal) : EMPTY_BYTES;
89973
89975
  const optInBytes = hasSingleHereStringRedir ? inBytes : void 0;
89974
89976
  const readFile = (p) => this.tryReadMemoryFileViewSync(resolvePath(rawState.cwd, p), true, true);
89975
- let csvOut = w0Plain === "csvcut" ? evalSyncCsvcut(inBytes, allArgs, readFile) : w0Plain === "csvgrep" ? evalSyncCsvgrep(inBytes, allArgs, readFile) : w0Plain === "csvlook" ? evalSyncCsvlook(optInBytes, allArgs, readFile) : w0Plain === "csvjson" ? evalSyncCsvjson(optInBytes, allArgs, readFile) : w0Plain === "csvsort" ? evalSyncCsvsort(optInBytes, allArgs, readFile) : w0Plain === "csvformat" ? evalSyncCsvformat(optInBytes, allArgs, readFile) : w0Plain === "csvstat" ? evalSyncCsvstat(optInBytes, allArgs, readFile) : w0Plain === "in2csv" ? evalSyncIn2csv(optInBytes, allArgs, readFile) : w0Plain === "csvstack" ? evalSyncCsvstack(optInBytes, allArgs, readFile) : w0Plain === "csvjoin" ? evalSyncCsvjoin(optInBytes, allArgs, readFile) : w0Plain === "dd" ? evalSyncDd(optInBytes, allArgs, readFile, (p, b) => {
89977
+ let csvOut = w0Plain === "csvcut" ? evalSyncCsvcut(optInBytes, allArgs, readFile) : w0Plain === "csvgrep" ? evalSyncCsvgrep(optInBytes, allArgs, readFile) : w0Plain === "csvlook" ? evalSyncCsvlook(optInBytes, allArgs, readFile) : w0Plain === "csvjson" ? evalSyncCsvjson(optInBytes, allArgs, readFile) : w0Plain === "csvsort" ? evalSyncCsvsort(optInBytes, allArgs, readFile) : w0Plain === "csvformat" ? evalSyncCsvformat(optInBytes, allArgs, readFile) : w0Plain === "csvstat" ? evalSyncCsvstat(optInBytes, allArgs, readFile) : w0Plain === "in2csv" ? evalSyncIn2csv(optInBytes, allArgs, readFile) : w0Plain === "csvstack" ? evalSyncCsvstack(optInBytes, allArgs, readFile) : w0Plain === "csvjoin" ? evalSyncCsvjoin(optInBytes, allArgs, readFile) : w0Plain === "dd" ? evalSyncDd(optInBytes, allArgs, readFile, (p, b) => {
89976
89978
  try {
89977
89979
  if (this._inSyncLoopPreflight) return Boolean(this.canFastMemoryRedirect && this._isMemoryBackingFs);
89978
89980
  return tryWriteMemoryFileSync(this.backingFs, resolvePath(rawState.cwd, p), b, false, 438 & ~(rawState.umask ?? 18), this.commandSignal);
@@ -34102,11 +34102,11 @@ export class Runtime {
34102
34102
  "LC_PAPER", "LC_NAME", "LC_ADDRESS", "LC_TELEPHONE", "LC_MEASUREMENT", "LC_IDENTIFICATION"
34103
34103
  ]) {
34104
34104
  if (lcAll)
34105
- lines.push(`${cat}=${lcAll}`);
34105
+ lines.push(`${cat}="${lcAll}"`);
34106
34106
  else if (getEnv(cat))
34107
34107
  lines.push(`${cat}=${getEnv(cat)}`);
34108
34108
  else
34109
- lines.push(`${cat}="${lang}"`);
34109
+ lines.push(`${cat}="${lang || "C.UTF-8"}"`);
34110
34110
  }
34111
34111
  lines.push(`LC_ALL=${lcAll ?? ""}`);
34112
34112
  return lines.join("\n");
@@ -37741,9 +37741,9 @@ export class Runtime {
37741
37741
  const optInBytes = hasSingleHereStringRedir ? inBytes : undefined;
37742
37742
  const readFile = (p) => this.tryReadMemoryFileViewSync(resolvePath(rawState.cwd, p), true, true);
37743
37743
  let csvOut = w0Plain === "csvcut"
37744
- ? evalSyncCsvcut(inBytes, allArgs, readFile)
37744
+ ? evalSyncCsvcut(optInBytes, allArgs, readFile)
37745
37745
  : w0Plain === "csvgrep"
37746
- ? evalSyncCsvgrep(inBytes, allArgs, readFile)
37746
+ ? evalSyncCsvgrep(optInBytes, allArgs, readFile)
37747
37747
  : w0Plain === "csvlook"
37748
37748
  ? evalSyncCsvlook(optInBytes, allArgs, readFile)
37749
37749
  : w0Plain === "csvjson"