compress-pdf-lib 1.0.0 → 1.0.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/compress.js +18 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compress-pdf-lib",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Client-side PDF compression: pdf.js render + mozjpeg (WASM) encoding via a parallel worker pool + pdf-lib rebuild. No server, no UI. Ships as raw ESM source for Vite-based apps (React + Vite, Astro).",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/compress.js CHANGED
@@ -252,9 +252,20 @@ async function processPage(pdf, pool, pageNumber, totalPages, { quality, resolut
252
252
 
253
253
  const largestDimension = Math.max(pdfWidth, pdfHeight);
254
254
 
255
- let scale = resolution / largestDimension;
256
- scale = Math.max(scale, 0.25);
257
- scale = Math.min(scale, 3);
255
+ let scale;
256
+
257
+ if (resolution === "original" || resolution === Infinity) {
258
+ /*
259
+ * No downscaling — render at the max allowed multiplier so page
260
+ * quality is limited only by the JPEG quality setting, not by
261
+ * resizing.
262
+ */
263
+ scale = 3;
264
+ } else {
265
+ scale = resolution / largestDimension;
266
+ scale = Math.max(scale, 0.25);
267
+ scale = Math.min(scale, 3);
268
+ }
258
269
 
259
270
  const viewport = page.getViewport({ scale });
260
271
  const width = Math.ceil(viewport.width);
@@ -475,7 +486,9 @@ async function buildPdf(compressedPages, { originalBytes, startedAt, workersUsed
475
486
  * @param {File|Blob|ArrayBuffer|ArrayBufferView} input
476
487
  * @param {Object} [options]
477
488
  * @param {number} [options.quality=65] - JPEG quality, 0-100
478
- * @param {number} [options.resolution=1600] - max px on the longest page side
489
+ * @param {number|"original"} [options.resolution=1600] - max px on the longest
490
+ * page side. Pass "original" (or Infinity) to skip downscaling entirely and
491
+ * rely on `quality` alone — renders at the max supported multiplier (3x).
479
492
  * @param {number} [options.workers] - override auto-detected worker count
480
493
  * @param {(update: object) => void} [options.onProgress] - optional progress callback
481
494
  * @returns {Promise<{file: File|Blob, stats: object}>}
@@ -534,4 +547,4 @@ export async function compressPDF(input, options = {}) {
534
547
 
535
548
  pool.destroy();
536
549
  }
537
- }
550
+ }