pdf-parser.js 5.2.18 → 5.2.20

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.
@@ -64,9 +64,8 @@ function filterBpp(bitDepth, channels) {
64
64
  }
65
65
  function unpackRow(rowBytes, width, channels, bitDepth) {
66
66
  const sampleCount = width * channels;
67
- const samples = new Array(sampleCount);
68
- if (bitDepth === 8) for (let i = 0; i < sampleCount; i++) samples[i] = rowBytes[i];
69
- else if (bitDepth === 16) for (let i = 0; i < sampleCount; i++) samples[i] = rowBytes[i * 2];
67
+ const samples = Array.from({ length: sampleCount });
68
+ if (bitDepth === 16) for (let i = 0; i < sampleCount; i++) samples[i] = rowBytes[i * 2];
70
69
  else {
71
70
  const mask = (1 << bitDepth) - 1;
72
71
  for (let i = 0; i < sampleCount; i++) {
@@ -146,7 +145,6 @@ function buildRawImage(ihdr, channels, bytesPerRow, unfiltered, palette, trns) {
146
145
  }
147
146
  } else if (colorType === 3) {
148
147
  const index = samples[pixelBase];
149
- if (palette === void 0) throw new Error("indexed-colour PNG has no PLTE chunk");
150
148
  data[outBase] = palette[index * 3];
151
149
  data[outBase + 1] = palette[index * 3 + 1];
152
150
  data[outBase + 2] = palette[index * 3 + 2];
@@ -164,12 +162,7 @@ function buildRawImage(ihdr, channels, bytesPerRow, unfiltered, palette, trns) {
164
162
  }
165
163
  }
166
164
  }
167
- return alpha === void 0 ? {
168
- width,
169
- height,
170
- channels: outChannels,
171
- data
172
- } : {
165
+ return {
173
166
  width,
174
167
  height,
175
168
  channels: outChannels,
@@ -63,9 +63,8 @@ function filterBpp(bitDepth, channels) {
63
63
  }
64
64
  function unpackRow(rowBytes, width, channels, bitDepth) {
65
65
  const sampleCount = width * channels;
66
- const samples = new Array(sampleCount);
67
- if (bitDepth === 8) for (let i = 0; i < sampleCount; i++) samples[i] = rowBytes[i];
68
- else if (bitDepth === 16) for (let i = 0; i < sampleCount; i++) samples[i] = rowBytes[i * 2];
66
+ const samples = Array.from({ length: sampleCount });
67
+ if (bitDepth === 16) for (let i = 0; i < sampleCount; i++) samples[i] = rowBytes[i * 2];
69
68
  else {
70
69
  const mask = (1 << bitDepth) - 1;
71
70
  for (let i = 0; i < sampleCount; i++) {
@@ -145,7 +144,6 @@ function buildRawImage(ihdr, channels, bytesPerRow, unfiltered, palette, trns) {
145
144
  }
146
145
  } else if (colorType === 3) {
147
146
  const index = samples[pixelBase];
148
- if (palette === void 0) throw new Error("indexed-colour PNG has no PLTE chunk");
149
147
  data[outBase] = palette[index * 3];
150
148
  data[outBase + 1] = palette[index * 3 + 1];
151
149
  data[outBase + 2] = palette[index * 3 + 2];
@@ -163,12 +161,7 @@ function buildRawImage(ihdr, channels, bytesPerRow, unfiltered, palette, trns) {
163
161
  }
164
162
  }
165
163
  }
166
- return alpha === void 0 ? {
167
- width,
168
- height,
169
- channels: outChannels,
170
- data
171
- } : {
164
+ return {
172
165
  width,
173
166
  height,
174
167
  channels: outChannels,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-parser.js",
3
- "version": "5.2.18",
3
+ "version": "5.2.20",
4
4
  "description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {