@stencil/core 2.17.4 → 2.18.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 (88) hide show
  1. package/cli/index.cjs +285 -220
  2. package/cli/index.d.ts +1 -0
  3. package/cli/index.js +285 -220
  4. package/cli/package.json +1 -1
  5. package/compiler/lib.dom.d.ts +620 -89
  6. package/compiler/lib.dom.iterable.d.ts +27 -3
  7. package/compiler/lib.es2015.core.d.ts +3 -3
  8. package/compiler/lib.es2015.iterable.d.ts +2 -1
  9. package/compiler/lib.es2015.reflect.d.ts +1 -1
  10. package/compiler/lib.es2020.bigint.d.ts +7 -5
  11. package/compiler/lib.es2020.d.ts +2 -0
  12. package/compiler/lib.es2020.date.d.ts +44 -0
  13. package/compiler/lib.es2020.intl.d.ts +51 -11
  14. package/compiler/lib.es2020.number.d.ts +30 -0
  15. package/compiler/lib.es2021.intl.d.ts +106 -4
  16. package/compiler/lib.es2022.array.d.ts +123 -0
  17. package/compiler/lib.es2022.d.ts +26 -0
  18. package/compiler/lib.es2022.error.d.ts +75 -0
  19. package/compiler/lib.es2022.full.d.ts +25 -0
  20. package/compiler/lib.es2022.intl.d.ts +111 -0
  21. package/compiler/lib.es2022.object.d.ts +28 -0
  22. package/compiler/lib.es2022.string.d.ts +27 -0
  23. package/compiler/lib.es5.d.ts +25 -19
  24. package/compiler/lib.esnext.d.ts +1 -1
  25. package/compiler/lib.esnext.intl.d.ts +4 -1
  26. package/compiler/lib.webworker.d.ts +236 -40
  27. package/compiler/lib.webworker.iterable.d.ts +10 -3
  28. package/compiler/package.json +1 -1
  29. package/compiler/stencil.d.ts +2 -2
  30. package/compiler/stencil.js +47263 -45624
  31. package/compiler/stencil.min.js +2 -2
  32. package/compiler/sys/in-memory-fs.d.ts +218 -0
  33. package/dependencies.json +10 -1
  34. package/dev-server/client/index.d.ts +2 -2
  35. package/dev-server/client/index.js +241 -241
  36. package/dev-server/client/package.json +1 -1
  37. package/dev-server/connector.html +3 -3
  38. package/dev-server/index.d.ts +1 -1
  39. package/dev-server/index.js +2 -2
  40. package/dev-server/package.json +1 -1
  41. package/dev-server/server-process.js +1198 -1167
  42. package/internal/app-data/package.json +1 -1
  43. package/internal/client/css-shim.js +2 -2
  44. package/internal/client/dom.js +1 -1
  45. package/internal/client/index.js +1022 -824
  46. package/internal/client/package.json +1 -1
  47. package/internal/client/patch-browser.js +1 -1
  48. package/internal/client/patch-esm.js +1 -1
  49. package/internal/client/polyfills/css-shim.js +1 -1
  50. package/internal/client/shadow-css.js +1 -1
  51. package/internal/hydrate/index.js +119 -119
  52. package/internal/hydrate/package.json +1 -1
  53. package/internal/hydrate/runner.d.ts +1 -1
  54. package/internal/hydrate/runner.js +100 -100
  55. package/internal/package.json +1 -1
  56. package/internal/stencil-core/index.d.ts +8 -10
  57. package/internal/stencil-private.d.ts +77 -138
  58. package/internal/stencil-public-compiler.d.ts +44 -10
  59. package/internal/stencil-public-runtime.d.ts +15 -4
  60. package/internal/testing/index.js +148 -148
  61. package/internal/testing/package.json +1 -1
  62. package/mock-doc/index.cjs +534 -518
  63. package/mock-doc/index.d.ts +13 -12
  64. package/mock-doc/index.js +534 -518
  65. package/mock-doc/package.json +1 -1
  66. package/package.json +23 -32
  67. package/readme.md +27 -33
  68. package/screenshot/index.d.ts +1 -1
  69. package/screenshot/index.js +13 -13
  70. package/screenshot/package.json +1 -1
  71. package/screenshot/pixel-match.js +983 -849
  72. package/sys/node/glob.js +1 -1
  73. package/sys/node/index.d.ts +2 -0
  74. package/sys/node/index.js +374 -373
  75. package/sys/node/package.json +1 -1
  76. package/sys/node/worker.js +1 -1
  77. package/testing/index.d.ts +6 -6
  78. package/testing/index.js +427 -441
  79. package/testing/jest/jest-config.d.ts +1 -1
  80. package/testing/matchers/index.d.ts +3 -3
  81. package/testing/mock-fetch.d.ts +1 -1
  82. package/testing/mocks.d.ts +2 -2
  83. package/testing/package.json +1 -1
  84. package/testing/puppeteer/puppeteer-element.d.ts +2 -2
  85. package/testing/puppeteer/puppeteer-events.d.ts +1 -1
  86. package/testing/testing-logger.d.ts +1 -1
  87. package/testing/testing-utils.d.ts +5 -4
  88. package/testing/testing.d.ts +1 -1
@@ -18,44 +18,78 @@ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
18
18
 
19
19
  var pixelmatch_1 = pixelmatch;
20
20
 
21
+ const defaultOptions = {
22
+ threshold: 0.1, // matching threshold (0 to 1); smaller is more sensitive
23
+ includeAA: false, // whether to skip anti-aliasing detection
24
+ alpha: 0.1, // opacity of original image in diff output
25
+ aaColor: [255, 255, 0], // color of anti-aliased pixels in diff output
26
+ diffColor: [255, 0, 0], // color of different pixels in diff output
27
+ diffColorAlt: null, // whether to detect dark on light differences between img1 and img2 and set an alternative color to differentiate between the two
28
+ diffMask: false // draw the diff over a transparent background (a mask)
29
+ };
30
+
21
31
  function pixelmatch(img1, img2, output, width, height, options) {
22
32
 
23
- if (!options) options = {};
33
+ if (!isPixelData(img1) || !isPixelData(img2) || (output && !isPixelData(output)))
34
+ throw new Error('Image data: Uint8Array, Uint8ClampedArray or Buffer expected.');
35
+
36
+ if (img1.length !== img2.length || (output && output.length !== img1.length))
37
+ throw new Error('Image sizes do not match.');
38
+
39
+ if (img1.length !== width * height * 4) throw new Error('Image data size does not match width/height.');
24
40
 
25
- var threshold = options.threshold === undefined ? 0.1 : options.threshold;
41
+ options = Object.assign({}, defaultOptions, options);
42
+
43
+ // check if images are identical
44
+ const len = width * height;
45
+ const a32 = new Uint32Array(img1.buffer, img1.byteOffset, len);
46
+ const b32 = new Uint32Array(img2.buffer, img2.byteOffset, len);
47
+ let identical = true;
48
+
49
+ for (let i = 0; i < len; i++) {
50
+ if (a32[i] !== b32[i]) { identical = false; break; }
51
+ }
52
+ if (identical) { // fast path if identical
53
+ if (output && !options.diffMask) {
54
+ for (let i = 0; i < len; i++) drawGrayPixel(img1, 4 * i, options.alpha, output);
55
+ }
56
+ return 0;
57
+ }
26
58
 
27
59
  // maximum acceptable square distance between two colors;
28
60
  // 35215 is the maximum possible value for the YIQ difference metric
29
- var maxDelta = 35215 * threshold * threshold,
30
- diff = 0;
61
+ const maxDelta = 35215 * options.threshold * options.threshold;
62
+ let diff = 0;
31
63
 
32
64
  // compare each pixel of one image against the other one
33
- for (var y = 0; y < height; y++) {
34
- for (var x = 0; x < width; x++) {
65
+ for (let y = 0; y < height; y++) {
66
+ for (let x = 0; x < width; x++) {
35
67
 
36
- var pos = (y * width + x) * 4;
68
+ const pos = (y * width + x) * 4;
37
69
 
38
- // squared YUV distance between colors at this pixel position
39
- var delta = colorDelta(img1, img2, pos, pos);
70
+ // squared YUV distance between colors at this pixel position, negative if the img2 pixel is darker
71
+ const delta = colorDelta(img1, img2, pos, pos);
40
72
 
41
73
  // the color difference is above the threshold
42
- if (delta > maxDelta) {
74
+ if (Math.abs(delta) > maxDelta) {
43
75
  // check it's a real rendering difference or just anti-aliasing
44
76
  if (!options.includeAA && (antialiased(img1, x, y, width, height, img2) ||
45
- antialiased(img2, x, y, width, height, img1))) {
77
+ antialiased(img2, x, y, width, height, img1))) {
46
78
  // one of the pixels is anti-aliasing; draw as yellow and do not count as difference
47
- if (output) drawPixel(output, pos, 255, 255, 0);
79
+ // note that we do not include such pixels in a mask
80
+ if (output && !options.diffMask) drawPixel(output, pos, ...options.aaColor);
48
81
 
49
82
  } else {
50
- // found substantial difference not caused by anti-aliasing; draw it as red
51
- if (output) drawPixel(output, pos, 255, 0, 0);
83
+ // found substantial difference not caused by anti-aliasing; draw it as such
84
+ if (output) {
85
+ drawPixel(output, pos, ...(delta < 0 && options.diffColorAlt || options.diffColor));
86
+ }
52
87
  diff++;
53
88
  }
54
89
 
55
90
  } else if (output) {
56
91
  // pixels are similar; draw background as grayscale image blended with white
57
- var val = blend(grayPixel(img1, pos), 0.1);
58
- drawPixel(output, pos, val, val, val);
92
+ if (!options.diffMask) drawGrayPixel(img1, pos, options.alpha, output);
59
93
  }
60
94
  }
61
95
  }
@@ -64,48 +98,47 @@ function pixelmatch(img1, img2, output, width, height, options) {
64
98
  return diff;
65
99
  }
66
100
 
101
+ function isPixelData(arr) {
102
+ // work around instanceof Uint8Array not working properly in some Jest environments
103
+ return ArrayBuffer.isView(arr) && arr.constructor.BYTES_PER_ELEMENT === 1;
104
+ }
105
+
67
106
  // check if a pixel is likely a part of anti-aliasing;
68
107
  // based on "Anti-aliased Pixel and Intensity Slope Detector" paper by V. Vysniauskas, 2009
69
108
 
70
109
  function antialiased(img, x1, y1, width, height, img2) {
71
- var x0 = Math.max(x1 - 1, 0),
72
- y0 = Math.max(y1 - 1, 0),
73
- x2 = Math.min(x1 + 1, width - 1),
74
- y2 = Math.min(y1 + 1, height - 1),
75
- pos = (y1 * width + x1) * 4,
76
- zeroes = 0,
77
- positives = 0,
78
- negatives = 0,
79
- min = 0,
80
- max = 0,
81
- minX, minY, maxX, maxY;
110
+ const x0 = Math.max(x1 - 1, 0);
111
+ const y0 = Math.max(y1 - 1, 0);
112
+ const x2 = Math.min(x1 + 1, width - 1);
113
+ const y2 = Math.min(y1 + 1, height - 1);
114
+ const pos = (y1 * width + x1) * 4;
115
+ let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
116
+ let min = 0;
117
+ let max = 0;
118
+ let minX, minY, maxX, maxY;
82
119
 
83
120
  // go through 8 adjacent pixels
84
- for (var x = x0; x <= x2; x++) {
85
- for (var y = y0; y <= y2; y++) {
121
+ for (let x = x0; x <= x2; x++) {
122
+ for (let y = y0; y <= y2; y++) {
86
123
  if (x === x1 && y === y1) continue;
87
124
 
88
125
  // brightness delta between the center pixel and adjacent one
89
- var delta = colorDelta(img, img, pos, (y * width + x) * 4, true);
126
+ const delta = colorDelta(img, img, pos, (y * width + x) * 4, true);
90
127
 
91
128
  // count the number of equal, darker and brighter adjacent pixels
92
- if (delta === 0) zeroes++;
93
- else if (delta < 0) negatives++;
94
- else if (delta > 0) positives++;
95
-
96
- // if found more than 2 equal siblings, it's definitely not anti-aliasing
97
- if (zeroes > 2) return false;
98
-
99
- if (!img2) continue;
129
+ if (delta === 0) {
130
+ zeroes++;
131
+ // if found more than 2 equal siblings, it's definitely not anti-aliasing
132
+ if (zeroes > 2) return false;
100
133
 
101
134
  // remember the darkest pixel
102
- if (delta < min) {
135
+ } else if (delta < min) {
103
136
  min = delta;
104
137
  minX = x;
105
138
  minY = y;
106
- }
139
+
107
140
  // remember the brightest pixel
108
- if (delta > max) {
141
+ } else if (delta > max) {
109
142
  max = delta;
110
143
  maxX = x;
111
144
  maxY = y;
@@ -113,40 +146,85 @@ function antialiased(img, x1, y1, width, height, img2) {
113
146
  }
114
147
  }
115
148
 
116
- if (!img2) return true;
117
-
118
149
  // if there are no both darker and brighter pixels among siblings, it's not anti-aliasing
119
- if (negatives === 0 || positives === 0) return false;
150
+ if (min === 0 || max === 0) return false;
120
151
 
121
- // if either the darkest or the brightest pixel has more than 2 equal siblings in both images
152
+ // if either the darkest or the brightest pixel has 3+ equal siblings in both images
122
153
  // (definitely not anti-aliased), this pixel is anti-aliased
123
- return (!antialiased(img, minX, minY, width, height) && !antialiased(img2, minX, minY, width, height)) ||
124
- (!antialiased(img, maxX, maxY, width, height) && !antialiased(img2, maxX, maxY, width, height));
154
+ return (hasManySiblings(img, minX, minY, width, height) && hasManySiblings(img2, minX, minY, width, height)) ||
155
+ (hasManySiblings(img, maxX, maxY, width, height) && hasManySiblings(img2, maxX, maxY, width, height));
156
+ }
157
+
158
+ // check if a pixel has 3+ adjacent pixels of the same color.
159
+ function hasManySiblings(img, x1, y1, width, height) {
160
+ const x0 = Math.max(x1 - 1, 0);
161
+ const y0 = Math.max(y1 - 1, 0);
162
+ const x2 = Math.min(x1 + 1, width - 1);
163
+ const y2 = Math.min(y1 + 1, height - 1);
164
+ const pos = (y1 * width + x1) * 4;
165
+ let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
166
+
167
+ // go through 8 adjacent pixels
168
+ for (let x = x0; x <= x2; x++) {
169
+ for (let y = y0; y <= y2; y++) {
170
+ if (x === x1 && y === y1) continue;
171
+
172
+ const pos2 = (y * width + x) * 4;
173
+ if (img[pos] === img[pos2] &&
174
+ img[pos + 1] === img[pos2 + 1] &&
175
+ img[pos + 2] === img[pos2 + 2] &&
176
+ img[pos + 3] === img[pos2 + 3]) zeroes++;
177
+
178
+ if (zeroes > 2) return true;
179
+ }
180
+ }
181
+
182
+ return false;
125
183
  }
126
184
 
127
185
  // calculate color difference according to the paper "Measuring perceived color difference
128
186
  // using YIQ NTSC transmission color space in mobile applications" by Y. Kotsarenko and F. Ramos
129
187
 
130
188
  function colorDelta(img1, img2, k, m, yOnly) {
131
- var a1 = img1[k + 3] / 255,
132
- a2 = img2[m + 3] / 255,
133
-
134
- r1 = blend(img1[k + 0], a1),
135
- g1 = blend(img1[k + 1], a1),
136
- b1 = blend(img1[k + 2], a1),
189
+ let r1 = img1[k + 0];
190
+ let g1 = img1[k + 1];
191
+ let b1 = img1[k + 2];
192
+ let a1 = img1[k + 3];
193
+
194
+ let r2 = img2[m + 0];
195
+ let g2 = img2[m + 1];
196
+ let b2 = img2[m + 2];
197
+ let a2 = img2[m + 3];
198
+
199
+ if (a1 === a2 && r1 === r2 && g1 === g2 && b1 === b2) return 0;
200
+
201
+ if (a1 < 255) {
202
+ a1 /= 255;
203
+ r1 = blend(r1, a1);
204
+ g1 = blend(g1, a1);
205
+ b1 = blend(b1, a1);
206
+ }
137
207
 
138
- r2 = blend(img2[m + 0], a2),
139
- g2 = blend(img2[m + 1], a2),
140
- b2 = blend(img2[m + 2], a2),
208
+ if (a2 < 255) {
209
+ a2 /= 255;
210
+ r2 = blend(r2, a2);
211
+ g2 = blend(g2, a2);
212
+ b2 = blend(b2, a2);
213
+ }
141
214
 
142
- y = rgb2y(r1, g1, b1) - rgb2y(r2, g2, b2);
215
+ const y1 = rgb2y(r1, g1, b1);
216
+ const y2 = rgb2y(r2, g2, b2);
217
+ const y = y1 - y2;
143
218
 
144
219
  if (yOnly) return y; // brightness difference only
145
220
 
146
- var i = rgb2i(r1, g1, b1) - rgb2i(r2, g2, b2),
147
- q = rgb2q(r1, g1, b1) - rgb2q(r2, g2, b2);
221
+ const i = rgb2i(r1, g1, b1) - rgb2i(r2, g2, b2);
222
+ const q = rgb2q(r1, g1, b1) - rgb2q(r2, g2, b2);
223
+
224
+ const delta = 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q;
148
225
 
149
- return 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q;
226
+ // encode whether the pixel lightens or darkens in the sign
227
+ return y1 > y2 ? -delta : delta;
150
228
  }
151
229
 
152
230
  function rgb2y(r, g, b) { return r * 0.29889531 + g * 0.58662247 + b * 0.11448223; }
@@ -165,12 +243,12 @@ function drawPixel(output, pos, r, g, b) {
165
243
  output[pos + 3] = 255;
166
244
  }
167
245
 
168
- function grayPixel(img, i) {
169
- var a = img[i + 3] / 255,
170
- r = blend(img[i + 0], a),
171
- g = blend(img[i + 1], a),
172
- b = blend(img[i + 2], a);
173
- return rgb2y(r, g, b);
246
+ function drawGrayPixel(img, i, alpha, output) {
247
+ const r = img[i + 0];
248
+ const g = img[i + 1];
249
+ const b = img[i + 2];
250
+ const val = blend(rgb2y(r, g, b), alpha * img[i + 3] / 255);
251
+ drawPixel(output, i, val, val, val);
174
252
  }
175
253
 
176
254
  function createCommonjsModule(fn, basedir, module) {
@@ -192,9 +270,7 @@ var chunkstream = createCommonjsModule(function (module) {
192
270
 
193
271
 
194
272
 
195
-
196
-
197
- var ChunkStream = module.exports = function() {
273
+ let ChunkStream = (module.exports = function () {
198
274
  Stream__default['default'].call(this);
199
275
 
200
276
  this._buffers = [];
@@ -203,45 +279,43 @@ var ChunkStream = module.exports = function() {
203
279
  this._reads = [];
204
280
  this._paused = false;
205
281
 
206
- this._encoding = 'utf8';
282
+ this._encoding = "utf8";
207
283
  this.writable = true;
208
- };
284
+ });
209
285
  util__default['default'].inherits(ChunkStream, Stream__default['default']);
210
286
 
211
-
212
- ChunkStream.prototype.read = function(length, callback) {
213
-
287
+ ChunkStream.prototype.read = function (length, callback) {
214
288
  this._reads.push({
215
289
  length: Math.abs(length), // if length < 0 then at most this length
216
290
  allowLess: length < 0,
217
- func: callback
291
+ func: callback,
218
292
  });
219
293
 
220
- process.nextTick(function() {
221
- this._process();
294
+ process.nextTick(
295
+ function () {
296
+ this._process();
222
297
 
223
- // its paused and there is not enought data then ask for more
224
- if (this._paused && this._reads.length > 0) {
225
- this._paused = false;
298
+ // its paused and there is not enought data then ask for more
299
+ if (this._paused && this._reads && this._reads.length > 0) {
300
+ this._paused = false;
226
301
 
227
- this.emit('drain');
228
- }
229
- }.bind(this));
302
+ this.emit("drain");
303
+ }
304
+ }.bind(this)
305
+ );
230
306
  };
231
307
 
232
- ChunkStream.prototype.write = function(data, encoding) {
233
-
308
+ ChunkStream.prototype.write = function (data, encoding) {
234
309
  if (!this.writable) {
235
- this.emit('error', new Error('Stream not writable'));
310
+ this.emit("error", new Error("Stream not writable"));
236
311
  return false;
237
312
  }
238
313
 
239
- var dataBuffer;
314
+ let dataBuffer;
240
315
  if (Buffer.isBuffer(data)) {
241
316
  dataBuffer = data;
242
- }
243
- else {
244
- dataBuffer = new Buffer(data, encoding || this._encoding);
317
+ } else {
318
+ dataBuffer = Buffer.from(data, encoding || this._encoding);
245
319
  }
246
320
 
247
321
  this._buffers.push(dataBuffer);
@@ -257,8 +331,7 @@ ChunkStream.prototype.write = function(data, encoding) {
257
331
  return this.writable && !this._paused;
258
332
  };
259
333
 
260
- ChunkStream.prototype.end = function(data, encoding) {
261
-
334
+ ChunkStream.prototype.end = function (data, encoding) {
262
335
  if (data) {
263
336
  this.write(data, encoding);
264
337
  }
@@ -273,8 +346,7 @@ ChunkStream.prototype.end = function(data, encoding) {
273
346
  // enqueue or handle end
274
347
  if (this._buffers.length === 0) {
275
348
  this._end();
276
- }
277
- else {
349
+ } else {
278
350
  this._buffers.push(null);
279
351
  this._process();
280
352
  }
@@ -282,19 +354,15 @@ ChunkStream.prototype.end = function(data, encoding) {
282
354
 
283
355
  ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
284
356
 
285
- ChunkStream.prototype._end = function() {
286
-
357
+ ChunkStream.prototype._end = function () {
287
358
  if (this._reads.length > 0) {
288
- this.emit('error',
289
- new Error('Unexpected end of input')
290
- );
359
+ this.emit("error", new Error("Unexpected end of input"));
291
360
  }
292
361
 
293
362
  this.destroy();
294
363
  };
295
364
 
296
- ChunkStream.prototype.destroy = function() {
297
-
365
+ ChunkStream.prototype.destroy = function () {
298
366
  if (!this._buffers) {
299
367
  return;
300
368
  }
@@ -303,26 +371,23 @@ ChunkStream.prototype.destroy = function() {
303
371
  this._reads = null;
304
372
  this._buffers = null;
305
373
 
306
- this.emit('close');
374
+ this.emit("close");
307
375
  };
308
376
 
309
- ChunkStream.prototype._processReadAllowingLess = function(read) {
377
+ ChunkStream.prototype._processReadAllowingLess = function (read) {
310
378
  // ok there is any data so that we can satisfy this request
311
379
  this._reads.shift(); // == read
312
380
 
313
381
  // first we need to peek into first buffer
314
- var smallerBuf = this._buffers[0];
382
+ let smallerBuf = this._buffers[0];
315
383
 
316
384
  // ok there is more data than we need
317
385
  if (smallerBuf.length > read.length) {
318
-
319
386
  this._buffered -= read.length;
320
387
  this._buffers[0] = smallerBuf.slice(read.length);
321
388
 
322
389
  read.func.call(this, smallerBuf.slice(0, read.length));
323
-
324
- }
325
- else {
390
+ } else {
326
391
  // ok this is less than maximum length so use it all
327
392
  this._buffered -= smallerBuf.length;
328
393
  this._buffers.shift(); // == smallerBuf
@@ -331,18 +396,17 @@ ChunkStream.prototype._processReadAllowingLess = function(read) {
331
396
  }
332
397
  };
333
398
 
334
- ChunkStream.prototype._processRead = function(read) {
399
+ ChunkStream.prototype._processRead = function (read) {
335
400
  this._reads.shift(); // == read
336
401
 
337
- var pos = 0;
338
- var count = 0;
339
- var data = new Buffer(read.length);
402
+ let pos = 0;
403
+ let count = 0;
404
+ let data = Buffer.alloc(read.length);
340
405
 
341
406
  // create buffer for all data
342
407
  while (pos < read.length) {
343
-
344
- var buf = this._buffers[count++];
345
- var len = Math.min(buf.length, read.length - pos);
408
+ let buf = this._buffers[count++];
409
+ let len = Math.min(buf.length, read.length - pos);
346
410
 
347
411
  buf.copy(data, pos, 0, len);
348
412
  pos += len;
@@ -363,25 +427,20 @@ ChunkStream.prototype._processRead = function(read) {
363
427
  read.func.call(this, data);
364
428
  };
365
429
 
366
- ChunkStream.prototype._process = function() {
367
-
430
+ ChunkStream.prototype._process = function () {
368
431
  try {
369
432
  // as long as there is any data and read requests
370
433
  while (this._buffered > 0 && this._reads && this._reads.length > 0) {
371
-
372
- var read = this._reads[0];
434
+ let read = this._reads[0];
373
435
 
374
436
  // read any data (but no more than length)
375
437
  if (read.allowLess) {
376
438
  this._processReadAllowingLess(read);
377
-
378
- }
379
- else if (this._buffered >= read.length) {
439
+ } else if (this._buffered >= read.length) {
380
440
  // ok we can meet some expectations
381
441
 
382
442
  this._processRead(read);
383
- }
384
- else {
443
+ } else {
385
444
  // not enought data to satisfy first request in queue
386
445
  // so we need to wait for more
387
446
  break;
@@ -391,9 +450,8 @@ ChunkStream.prototype._process = function() {
391
450
  if (this._buffers && !this.writable) {
392
451
  this._end();
393
452
  }
394
- }
395
- catch (ex) {
396
- this.emit('error', ex);
453
+ } catch (ex) {
454
+ this.emit("error", ex);
397
455
  }
398
456
  };
399
457
  });
@@ -409,61 +467,65 @@ ChunkStream.prototype._process = function() {
409
467
  // 6 5 6 5 6 5 6 5 6
410
468
  // 7 7 7 7 7 7 7 7 7
411
469
 
412
-
413
- var imagePasses = [
414
- { // pass 1 - 1px
470
+ let imagePasses = [
471
+ {
472
+ // pass 1 - 1px
415
473
  x: [0],
416
- y: [0]
474
+ y: [0],
417
475
  },
418
- { // pass 2 - 1px
476
+ {
477
+ // pass 2 - 1px
419
478
  x: [4],
420
- y: [0]
479
+ y: [0],
421
480
  },
422
- { // pass 3 - 2px
481
+ {
482
+ // pass 3 - 2px
423
483
  x: [0, 4],
424
- y: [4]
484
+ y: [4],
425
485
  },
426
- { // pass 4 - 4px
486
+ {
487
+ // pass 4 - 4px
427
488
  x: [2, 6],
428
- y: [0, 4]
489
+ y: [0, 4],
429
490
  },
430
- { // pass 5 - 8px
491
+ {
492
+ // pass 5 - 8px
431
493
  x: [0, 2, 4, 6],
432
- y: [2, 6]
494
+ y: [2, 6],
433
495
  },
434
- { // pass 6 - 16px
496
+ {
497
+ // pass 6 - 16px
435
498
  x: [1, 3, 5, 7],
436
- y: [0, 2, 4, 6]
499
+ y: [0, 2, 4, 6],
437
500
  },
438
- { // pass 7 - 32px
501
+ {
502
+ // pass 7 - 32px
439
503
  x: [0, 1, 2, 3, 4, 5, 6, 7],
440
- y: [1, 3, 5, 7]
441
- }
504
+ y: [1, 3, 5, 7],
505
+ },
442
506
  ];
443
507
 
444
- var getImagePasses = function(width, height) {
445
- var images = [];
446
- var xLeftOver = width % 8;
447
- var yLeftOver = height % 8;
448
- var xRepeats = (width - xLeftOver) / 8;
449
- var yRepeats = (height - yLeftOver) / 8;
450
- for (var i = 0; i < imagePasses.length; i++) {
451
- var pass = imagePasses[i];
452
- var passWidth = xRepeats * pass.x.length;
453
- var passHeight = yRepeats * pass.y.length;
454
- for (var j = 0; j < pass.x.length; j++) {
508
+ var getImagePasses = function (width, height) {
509
+ let images = [];
510
+ let xLeftOver = width % 8;
511
+ let yLeftOver = height % 8;
512
+ let xRepeats = (width - xLeftOver) / 8;
513
+ let yRepeats = (height - yLeftOver) / 8;
514
+ for (let i = 0; i < imagePasses.length; i++) {
515
+ let pass = imagePasses[i];
516
+ let passWidth = xRepeats * pass.x.length;
517
+ let passHeight = yRepeats * pass.y.length;
518
+ for (let j = 0; j < pass.x.length; j++) {
455
519
  if (pass.x[j] < xLeftOver) {
456
520
  passWidth++;
457
- }
458
- else {
521
+ } else {
459
522
  break;
460
523
  }
461
524
  }
462
- for (j = 0; j < pass.y.length; j++) {
525
+ for (let j = 0; j < pass.y.length; j++) {
463
526
  if (pass.y[j] < yLeftOver) {
464
527
  passHeight++;
465
- }
466
- else {
528
+ } else {
467
529
  break;
468
530
  }
469
531
  }
@@ -474,13 +536,17 @@ var getImagePasses = function(width, height) {
474
536
  return images;
475
537
  };
476
538
 
477
- var getInterlaceIterator = function(width) {
478
- return function(x, y, pass) {
479
- var outerXLeftOver = x % imagePasses[pass].x.length;
480
- var outerX = (((x - outerXLeftOver) / imagePasses[pass].x.length) * 8) + imagePasses[pass].x[outerXLeftOver];
481
- var outerYLeftOver = y % imagePasses[pass].y.length;
482
- var outerY = (((y - outerYLeftOver) / imagePasses[pass].y.length) * 8) + imagePasses[pass].y[outerYLeftOver];
483
- return (outerX * 4) + (outerY * width * 4);
539
+ var getInterlaceIterator = function (width) {
540
+ return function (x, y, pass) {
541
+ let outerXLeftOver = x % imagePasses[pass].x.length;
542
+ let outerX =
543
+ ((x - outerXLeftOver) / imagePasses[pass].x.length) * 8 +
544
+ imagePasses[pass].x[outerXLeftOver];
545
+ let outerYLeftOver = y % imagePasses[pass].y.length;
546
+ let outerY =
547
+ ((y - outerYLeftOver) / imagePasses[pass].y.length) * 8 +
548
+ imagePasses[pass].y[outerYLeftOver];
549
+ return outerX * 4 + outerY * width * 4;
484
550
  };
485
551
  };
486
552
 
@@ -489,20 +555,19 @@ var interlace = {
489
555
  getInterlaceIterator: getInterlaceIterator
490
556
  };
491
557
 
492
- var paethPredictor = function paethPredictor(left, above, upLeft) {
493
-
494
- var paeth = left + above - upLeft;
495
- var pLeft = Math.abs(paeth - left);
496
- var pAbove = Math.abs(paeth - above);
497
- var pUpLeft = Math.abs(paeth - upLeft);
498
-
499
- if (pLeft <= pAbove && pLeft <= pUpLeft) {
500
- return left;
501
- }
502
- if (pAbove <= pUpLeft) {
503
- return above;
504
- }
505
- return upLeft;
558
+ var paethPredictor = function paethPredictor(left, above, upLeft) {
559
+ let paeth = left + above - upLeft;
560
+ let pLeft = Math.abs(paeth - left);
561
+ let pAbove = Math.abs(paeth - above);
562
+ let pUpLeft = Math.abs(paeth - upLeft);
563
+
564
+ if (pLeft <= pAbove && pLeft <= pUpLeft) {
565
+ return left;
566
+ }
567
+ if (pAbove <= pUpLeft) {
568
+ return above;
569
+ }
570
+ return upLeft;
506
571
  };
507
572
 
508
573
  var filterParse = createCommonjsModule(function (module) {
@@ -511,20 +576,19 @@ var filterParse = createCommonjsModule(function (module) {
511
576
 
512
577
 
513
578
  function getByteWidth(width, bpp, depth) {
514
- var byteWidth = width * bpp;
579
+ let byteWidth = width * bpp;
515
580
  if (depth !== 8) {
516
581
  byteWidth = Math.ceil(byteWidth / (8 / depth));
517
582
  }
518
583
  return byteWidth;
519
584
  }
520
585
 
521
- var Filter = module.exports = function(bitmapInfo, dependencies) {
522
-
523
- var width = bitmapInfo.width;
524
- var height = bitmapInfo.height;
525
- var interlace$1 = bitmapInfo.interlace;
526
- var bpp = bitmapInfo.bpp;
527
- var depth = bitmapInfo.depth;
586
+ let Filter = (module.exports = function (bitmapInfo, dependencies) {
587
+ let width = bitmapInfo.width;
588
+ let height = bitmapInfo.height;
589
+ let interlace$1 = bitmapInfo.interlace;
590
+ let bpp = bitmapInfo.bpp;
591
+ let depth = bitmapInfo.depth;
528
592
 
529
593
  this.read = dependencies.read;
530
594
  this.write = dependencies.write;
@@ -533,20 +597,19 @@ var Filter = module.exports = function(bitmapInfo, dependencies) {
533
597
  this._imageIndex = 0;
534
598
  this._images = [];
535
599
  if (interlace$1) {
536
- var passes = interlace.getImagePasses(width, height);
537
- for (var i = 0; i < passes.length; i++) {
600
+ let passes = interlace.getImagePasses(width, height);
601
+ for (let i = 0; i < passes.length; i++) {
538
602
  this._images.push({
539
603
  byteWidth: getByteWidth(passes[i].width, bpp, depth),
540
604
  height: passes[i].height,
541
- lineIndex: 0
605
+ lineIndex: 0,
542
606
  });
543
607
  }
544
- }
545
- else {
608
+ } else {
546
609
  this._images.push({
547
610
  byteWidth: getByteWidth(width, bpp, depth),
548
611
  height: height,
549
- lineIndex: 0
612
+ lineIndex: 0,
550
613
  });
551
614
  }
552
615
 
@@ -556,86 +619,96 @@ var Filter = module.exports = function(bitmapInfo, dependencies) {
556
619
  // a pixel rather than just a different byte part. However if we are sub byte, we ignore.
557
620
  if (depth === 8) {
558
621
  this._xComparison = bpp;
559
- }
560
- else if (depth === 16) {
622
+ } else if (depth === 16) {
561
623
  this._xComparison = bpp * 2;
562
- }
563
- else {
624
+ } else {
564
625
  this._xComparison = 1;
565
626
  }
566
- };
627
+ });
567
628
 
568
- Filter.prototype.start = function() {
569
- this.read(this._images[this._imageIndex].byteWidth + 1, this._reverseFilterLine.bind(this));
629
+ Filter.prototype.start = function () {
630
+ this.read(
631
+ this._images[this._imageIndex].byteWidth + 1,
632
+ this._reverseFilterLine.bind(this)
633
+ );
570
634
  };
571
635
 
572
- Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
573
-
574
- var xComparison = this._xComparison;
575
- var xBiggerThan = xComparison - 1;
636
+ Filter.prototype._unFilterType1 = function (
637
+ rawData,
638
+ unfilteredLine,
639
+ byteWidth
640
+ ) {
641
+ let xComparison = this._xComparison;
642
+ let xBiggerThan = xComparison - 1;
576
643
 
577
- for (var x = 0; x < byteWidth; x++) {
578
- var rawByte = rawData[1 + x];
579
- var f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
644
+ for (let x = 0; x < byteWidth; x++) {
645
+ let rawByte = rawData[1 + x];
646
+ let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
580
647
  unfilteredLine[x] = rawByte + f1Left;
581
648
  }
582
649
  };
583
650
 
584
- Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
651
+ Filter.prototype._unFilterType2 = function (
652
+ rawData,
653
+ unfilteredLine,
654
+ byteWidth
655
+ ) {
656
+ let lastLine = this._lastLine;
585
657
 
586
- var lastLine = this._lastLine;
587
-
588
- for (var x = 0; x < byteWidth; x++) {
589
- var rawByte = rawData[1 + x];
590
- var f2Up = lastLine ? lastLine[x] : 0;
658
+ for (let x = 0; x < byteWidth; x++) {
659
+ let rawByte = rawData[1 + x];
660
+ let f2Up = lastLine ? lastLine[x] : 0;
591
661
  unfilteredLine[x] = rawByte + f2Up;
592
662
  }
593
663
  };
594
664
 
595
- Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
596
-
597
- var xComparison = this._xComparison;
598
- var xBiggerThan = xComparison - 1;
599
- var lastLine = this._lastLine;
665
+ Filter.prototype._unFilterType3 = function (
666
+ rawData,
667
+ unfilteredLine,
668
+ byteWidth
669
+ ) {
670
+ let xComparison = this._xComparison;
671
+ let xBiggerThan = xComparison - 1;
672
+ let lastLine = this._lastLine;
600
673
 
601
- for (var x = 0; x < byteWidth; x++) {
602
- var rawByte = rawData[1 + x];
603
- var f3Up = lastLine ? lastLine[x] : 0;
604
- var f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
605
- var f3Add = Math.floor((f3Left + f3Up) / 2);
674
+ for (let x = 0; x < byteWidth; x++) {
675
+ let rawByte = rawData[1 + x];
676
+ let f3Up = lastLine ? lastLine[x] : 0;
677
+ let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
678
+ let f3Add = Math.floor((f3Left + f3Up) / 2);
606
679
  unfilteredLine[x] = rawByte + f3Add;
607
680
  }
608
681
  };
609
682
 
610
- Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
611
-
612
- var xComparison = this._xComparison;
613
- var xBiggerThan = xComparison - 1;
614
- var lastLine = this._lastLine;
683
+ Filter.prototype._unFilterType4 = function (
684
+ rawData,
685
+ unfilteredLine,
686
+ byteWidth
687
+ ) {
688
+ let xComparison = this._xComparison;
689
+ let xBiggerThan = xComparison - 1;
690
+ let lastLine = this._lastLine;
615
691
 
616
- for (var x = 0; x < byteWidth; x++) {
617
- var rawByte = rawData[1 + x];
618
- var f4Up = lastLine ? lastLine[x] : 0;
619
- var f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
620
- var f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
621
- var f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
692
+ for (let x = 0; x < byteWidth; x++) {
693
+ let rawByte = rawData[1 + x];
694
+ let f4Up = lastLine ? lastLine[x] : 0;
695
+ let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
696
+ let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
697
+ let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
622
698
  unfilteredLine[x] = rawByte + f4Add;
623
699
  }
624
700
  };
625
701
 
626
- Filter.prototype._reverseFilterLine = function(rawData) {
627
-
628
- var filter = rawData[0];
629
- var unfilteredLine;
630
- var currentImage = this._images[this._imageIndex];
631
- var byteWidth = currentImage.byteWidth;
702
+ Filter.prototype._reverseFilterLine = function (rawData) {
703
+ let filter = rawData[0];
704
+ let unfilteredLine;
705
+ let currentImage = this._images[this._imageIndex];
706
+ let byteWidth = currentImage.byteWidth;
632
707
 
633
708
  if (filter === 0) {
634
709
  unfilteredLine = rawData.slice(1, byteWidth + 1);
635
- }
636
- else {
637
-
638
- unfilteredLine = new Buffer(byteWidth);
710
+ } else {
711
+ unfilteredLine = Buffer.alloc(byteWidth);
639
712
 
640
713
  switch (filter) {
641
714
  case 1:
@@ -651,7 +724,7 @@ Filter.prototype._reverseFilterLine = function(rawData) {
651
724
  this._unFilterType4(rawData, unfilteredLine, byteWidth);
652
725
  break;
653
726
  default:
654
- throw new Error('Unrecognised filter type - ' + filter);
727
+ throw new Error("Unrecognised filter type - " + filter);
655
728
  }
656
729
  }
657
730
 
@@ -662,16 +735,14 @@ Filter.prototype._reverseFilterLine = function(rawData) {
662
735
  this._lastLine = null;
663
736
  this._imageIndex++;
664
737
  currentImage = this._images[this._imageIndex];
665
- }
666
- else {
738
+ } else {
667
739
  this._lastLine = unfilteredLine;
668
740
  }
669
741
 
670
742
  if (currentImage) {
671
743
  // read, using the byte width that may be from the new current image
672
744
  this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
673
- }
674
- else {
745
+ } else {
675
746
  this._lastLine = null;
676
747
  this.complete();
677
748
  }
@@ -684,29 +755,27 @@ var filterParseAsync = createCommonjsModule(function (module) {
684
755
 
685
756
 
686
757
 
687
-
688
- var FilterAsync = module.exports = function(bitmapInfo) {
758
+ let FilterAsync = (module.exports = function (bitmapInfo) {
689
759
  chunkstream.call(this);
690
760
 
691
- var buffers = [];
692
- var that = this;
761
+ let buffers = [];
762
+ let that = this;
693
763
  this._filter = new filterParse(bitmapInfo, {
694
764
  read: this.read.bind(this),
695
- write: function(buffer) {
765
+ write: function (buffer) {
696
766
  buffers.push(buffer);
697
767
  },
698
- complete: function() {
699
- that.emit('complete', Buffer.concat(buffers));
700
- }
768
+ complete: function () {
769
+ that.emit("complete", Buffer.concat(buffers));
770
+ },
701
771
  });
702
772
 
703
773
  this._filter.start();
704
- };
774
+ });
705
775
  util__default['default'].inherits(FilterAsync, chunkstream);
706
776
  });
707
777
 
708
778
  var constants = {
709
-
710
779
  PNG_SIGNATURE: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a],
711
780
 
712
781
  TYPE_IHDR: 0x49484452,
@@ -731,52 +800,48 @@ var constants = {
731
800
  2: 3,
732
801
  3: 1,
733
802
  4: 2,
734
- 6: 4
803
+ 6: 4,
735
804
  },
736
805
 
737
- GAMMA_DIVISION: 100000
806
+ GAMMA_DIVISION: 100000,
738
807
  };
739
808
 
740
809
  var crc = createCommonjsModule(function (module) {
741
810
 
742
- var crcTable = [];
811
+ let crcTable = [];
743
812
 
744
- (function() {
745
- for (var i = 0; i < 256; i++) {
746
- var currentCrc = i;
747
- for (var j = 0; j < 8; j++) {
813
+ (function () {
814
+ for (let i = 0; i < 256; i++) {
815
+ let currentCrc = i;
816
+ for (let j = 0; j < 8; j++) {
748
817
  if (currentCrc & 1) {
749
818
  currentCrc = 0xedb88320 ^ (currentCrc >>> 1);
750
- }
751
- else {
819
+ } else {
752
820
  currentCrc = currentCrc >>> 1;
753
821
  }
754
822
  }
755
823
  crcTable[i] = currentCrc;
756
824
  }
757
- }());
825
+ })();
758
826
 
759
- var CrcCalculator = module.exports = function() {
827
+ let CrcCalculator = (module.exports = function () {
760
828
  this._crc = -1;
761
- };
762
-
763
- CrcCalculator.prototype.write = function(data) {
829
+ });
764
830
 
765
- for (var i = 0; i < data.length; i++) {
831
+ CrcCalculator.prototype.write = function (data) {
832
+ for (let i = 0; i < data.length; i++) {
766
833
  this._crc = crcTable[(this._crc ^ data[i]) & 0xff] ^ (this._crc >>> 8);
767
834
  }
768
835
  return true;
769
836
  };
770
837
 
771
- CrcCalculator.prototype.crc32 = function() {
838
+ CrcCalculator.prototype.crc32 = function () {
772
839
  return this._crc ^ -1;
773
840
  };
774
841
 
775
-
776
- CrcCalculator.crc32 = function(buf) {
777
-
778
- var crc = -1;
779
- for (var i = 0; i < buf.length; i++) {
842
+ CrcCalculator.crc32 = function (buf) {
843
+ let crc = -1;
844
+ for (let i = 0; i < buf.length; i++) {
780
845
  crc = crcTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
781
846
  }
782
847
  return crc ^ -1;
@@ -788,9 +853,7 @@ var parser = createCommonjsModule(function (module) {
788
853
 
789
854
 
790
855
 
791
-
792
- var Parser = module.exports = function(options, dependencies) {
793
-
856
+ let Parser = (module.exports = function (options, dependencies) {
794
857
  this._options = options;
795
858
  options.checkCRC = options.checkCRC !== false;
796
859
 
@@ -820,83 +883,78 @@ var Parser = module.exports = function(options, dependencies) {
820
883
  this.inflateData = dependencies.inflateData;
821
884
  this.finished = dependencies.finished;
822
885
  this.simpleTransparency = dependencies.simpleTransparency;
823
- this.headersFinished = dependencies.headersFinished || function() {};
824
- };
886
+ this.headersFinished = dependencies.headersFinished || function () {};
887
+ });
825
888
 
826
- Parser.prototype.start = function() {
827
- this.read(constants.PNG_SIGNATURE.length,
828
- this._parseSignature.bind(this)
829
- );
889
+ Parser.prototype.start = function () {
890
+ this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
830
891
  };
831
892
 
832
- Parser.prototype._parseSignature = function(data) {
833
-
834
- var signature = constants.PNG_SIGNATURE;
893
+ Parser.prototype._parseSignature = function (data) {
894
+ let signature = constants.PNG_SIGNATURE;
835
895
 
836
- for (var i = 0; i < signature.length; i++) {
896
+ for (let i = 0; i < signature.length; i++) {
837
897
  if (data[i] !== signature[i]) {
838
- this.error(new Error('Invalid file signature'));
898
+ this.error(new Error("Invalid file signature"));
839
899
  return;
840
900
  }
841
901
  }
842
902
  this.read(8, this._parseChunkBegin.bind(this));
843
903
  };
844
904
 
845
- Parser.prototype._parseChunkBegin = function(data) {
846
-
905
+ Parser.prototype._parseChunkBegin = function (data) {
847
906
  // chunk content length
848
- var length = data.readUInt32BE(0);
907
+ let length = data.readUInt32BE(0);
849
908
 
850
909
  // chunk type
851
- var type = data.readUInt32BE(4);
852
- var name = '';
853
- for (var i = 4; i < 8; i++) {
910
+ let type = data.readUInt32BE(4);
911
+ let name = "";
912
+ for (let i = 4; i < 8; i++) {
854
913
  name += String.fromCharCode(data[i]);
855
914
  }
856
915
 
857
916
  //console.log('chunk ', name, length);
858
917
 
859
918
  // chunk flags
860
- var ancillary = Boolean(data[4] & 0x20); // or critical
919
+ let ancillary = Boolean(data[4] & 0x20); // or critical
861
920
  // priv = Boolean(data[5] & 0x20), // or public
862
921
  // safeToCopy = Boolean(data[7] & 0x20); // or unsafe
863
922
 
864
923
  if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
865
- this.error(new Error('Expected IHDR on beggining'));
924
+ this.error(new Error("Expected IHDR on beggining"));
866
925
  return;
867
926
  }
868
927
 
869
928
  this._crc = new crc();
870
- this._crc.write(new Buffer(name));
929
+ this._crc.write(Buffer.from(name));
871
930
 
872
931
  if (this._chunks[type]) {
873
932
  return this._chunks[type](length);
874
933
  }
875
934
 
876
935
  if (!ancillary) {
877
- this.error(new Error('Unsupported critical chunk type ' + name));
936
+ this.error(new Error("Unsupported critical chunk type " + name));
878
937
  return;
879
938
  }
880
939
 
881
940
  this.read(length + 4, this._skipChunk.bind(this));
882
941
  };
883
942
 
884
- Parser.prototype._skipChunk = function(/*data*/) {
943
+ Parser.prototype._skipChunk = function (/*data*/) {
885
944
  this.read(8, this._parseChunkBegin.bind(this));
886
945
  };
887
946
 
888
- Parser.prototype._handleChunkEnd = function() {
947
+ Parser.prototype._handleChunkEnd = function () {
889
948
  this.read(4, this._parseChunkEnd.bind(this));
890
949
  };
891
950
 
892
- Parser.prototype._parseChunkEnd = function(data) {
893
-
894
- var fileCrc = data.readInt32BE(0);
895
- var calcCrc = this._crc.crc32();
951
+ Parser.prototype._parseChunkEnd = function (data) {
952
+ let fileCrc = data.readInt32BE(0);
953
+ let calcCrc = this._crc.crc32();
896
954
 
897
955
  // check CRC
898
956
  if (this._options.checkCRC && calcCrc !== fileCrc) {
899
- this.error(new Error('Crc error - ' + fileCrc + ' - ' + calcCrc));
957
+ this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
900
958
  return;
901
959
  }
902
960
 
@@ -905,50 +963,55 @@ Parser.prototype._parseChunkEnd = function(data) {
905
963
  }
906
964
  };
907
965
 
908
- Parser.prototype._handleIHDR = function(length) {
966
+ Parser.prototype._handleIHDR = function (length) {
909
967
  this.read(length, this._parseIHDR.bind(this));
910
968
  };
911
- Parser.prototype._parseIHDR = function(data) {
912
-
969
+ Parser.prototype._parseIHDR = function (data) {
913
970
  this._crc.write(data);
914
971
 
915
- var width = data.readUInt32BE(0);
916
- var height = data.readUInt32BE(4);
917
- var depth = data[8];
918
- var colorType = data[9]; // bits: 1 palette, 2 color, 4 alpha
919
- var compr = data[10];
920
- var filter = data[11];
921
- var interlace = data[12];
972
+ let width = data.readUInt32BE(0);
973
+ let height = data.readUInt32BE(4);
974
+ let depth = data[8];
975
+ let colorType = data[9]; // bits: 1 palette, 2 color, 4 alpha
976
+ let compr = data[10];
977
+ let filter = data[11];
978
+ let interlace = data[12];
922
979
 
923
980
  // console.log(' width', width, 'height', height,
924
981
  // 'depth', depth, 'colorType', colorType,
925
982
  // 'compr', compr, 'filter', filter, 'interlace', interlace
926
983
  // );
927
984
 
928
- if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
929
- this.error(new Error('Unsupported bit depth ' + depth));
985
+ if (
986
+ depth !== 8 &&
987
+ depth !== 4 &&
988
+ depth !== 2 &&
989
+ depth !== 1 &&
990
+ depth !== 16
991
+ ) {
992
+ this.error(new Error("Unsupported bit depth " + depth));
930
993
  return;
931
994
  }
932
995
  if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
933
- this.error(new Error('Unsupported color type'));
996
+ this.error(new Error("Unsupported color type"));
934
997
  return;
935
998
  }
936
999
  if (compr !== 0) {
937
- this.error(new Error('Unsupported compression method'));
1000
+ this.error(new Error("Unsupported compression method"));
938
1001
  return;
939
1002
  }
940
1003
  if (filter !== 0) {
941
- this.error(new Error('Unsupported filter method'));
1004
+ this.error(new Error("Unsupported filter method"));
942
1005
  return;
943
1006
  }
944
1007
  if (interlace !== 0 && interlace !== 1) {
945
- this.error(new Error('Unsupported interlace method'));
1008
+ this.error(new Error("Unsupported interlace method"));
946
1009
  return;
947
1010
  }
948
1011
 
949
1012
  this._colorType = colorType;
950
1013
 
951
- var bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
1014
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
952
1015
 
953
1016
  this._hasIHDR = true;
954
1017
 
@@ -961,30 +1024,23 @@ Parser.prototype._parseIHDR = function(data) {
961
1024
  color: Boolean(colorType & constants.COLORTYPE_COLOR),
962
1025
  alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
963
1026
  bpp: bpp,
964
- colorType: colorType
1027
+ colorType: colorType,
965
1028
  });
966
1029
 
967
1030
  this._handleChunkEnd();
968
1031
  };
969
1032
 
970
-
971
- Parser.prototype._handlePLTE = function(length) {
1033
+ Parser.prototype._handlePLTE = function (length) {
972
1034
  this.read(length, this._parsePLTE.bind(this));
973
1035
  };
974
- Parser.prototype._parsePLTE = function(data) {
975
-
1036
+ Parser.prototype._parsePLTE = function (data) {
976
1037
  this._crc.write(data);
977
1038
 
978
- var entries = Math.floor(data.length / 3);
1039
+ let entries = Math.floor(data.length / 3);
979
1040
  // console.log('Palette:', entries);
980
1041
 
981
- for (var i = 0; i < entries; i++) {
982
- this._palette.push([
983
- data[i * 3],
984
- data[i * 3 + 1],
985
- data[i * 3 + 2],
986
- 0xff
987
- ]);
1042
+ for (let i = 0; i < entries; i++) {
1043
+ this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 0xff]);
988
1044
  }
989
1045
 
990
1046
  this.palette(this._palette);
@@ -992,25 +1048,24 @@ Parser.prototype._parsePLTE = function(data) {
992
1048
  this._handleChunkEnd();
993
1049
  };
994
1050
 
995
- Parser.prototype._handleTRNS = function(length) {
1051
+ Parser.prototype._handleTRNS = function (length) {
996
1052
  this.simpleTransparency();
997
1053
  this.read(length, this._parseTRNS.bind(this));
998
1054
  };
999
- Parser.prototype._parseTRNS = function(data) {
1000
-
1055
+ Parser.prototype._parseTRNS = function (data) {
1001
1056
  this._crc.write(data);
1002
1057
 
1003
1058
  // palette
1004
1059
  if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
1005
1060
  if (this._palette.length === 0) {
1006
- this.error(new Error('Transparency chunk must be after palette'));
1061
+ this.error(new Error("Transparency chunk must be after palette"));
1007
1062
  return;
1008
1063
  }
1009
1064
  if (data.length > this._palette.length) {
1010
- this.error(new Error('More transparent colors than palette size'));
1065
+ this.error(new Error("More transparent colors than palette size"));
1011
1066
  return;
1012
1067
  }
1013
- for (var i = 0; i < data.length; i++) {
1068
+ for (let i = 0; i < data.length; i++) {
1014
1069
  this._palette[i][3] = data[i];
1015
1070
  }
1016
1071
  this.palette(this._palette);
@@ -1023,54 +1078,57 @@ Parser.prototype._parseTRNS = function(data) {
1023
1078
  this.transColor([data.readUInt16BE(0)]);
1024
1079
  }
1025
1080
  if (this._colorType === constants.COLORTYPE_COLOR) {
1026
- this.transColor([data.readUInt16BE(0), data.readUInt16BE(2), data.readUInt16BE(4)]);
1081
+ this.transColor([
1082
+ data.readUInt16BE(0),
1083
+ data.readUInt16BE(2),
1084
+ data.readUInt16BE(4),
1085
+ ]);
1027
1086
  }
1028
1087
 
1029
1088
  this._handleChunkEnd();
1030
1089
  };
1031
1090
 
1032
- Parser.prototype._handleGAMA = function(length) {
1091
+ Parser.prototype._handleGAMA = function (length) {
1033
1092
  this.read(length, this._parseGAMA.bind(this));
1034
1093
  };
1035
- Parser.prototype._parseGAMA = function(data) {
1036
-
1094
+ Parser.prototype._parseGAMA = function (data) {
1037
1095
  this._crc.write(data);
1038
1096
  this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
1039
1097
 
1040
1098
  this._handleChunkEnd();
1041
1099
  };
1042
1100
 
1043
- Parser.prototype._handleIDAT = function(length) {
1101
+ Parser.prototype._handleIDAT = function (length) {
1044
1102
  if (!this._emittedHeadersFinished) {
1045
1103
  this._emittedHeadersFinished = true;
1046
1104
  this.headersFinished();
1047
1105
  }
1048
1106
  this.read(-length, this._parseIDAT.bind(this, length));
1049
1107
  };
1050
- Parser.prototype._parseIDAT = function(length, data) {
1051
-
1108
+ Parser.prototype._parseIDAT = function (length, data) {
1052
1109
  this._crc.write(data);
1053
1110
 
1054
- if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
1055
- throw new Error('Expected palette not found');
1111
+ if (
1112
+ this._colorType === constants.COLORTYPE_PALETTE_COLOR &&
1113
+ this._palette.length === 0
1114
+ ) {
1115
+ throw new Error("Expected palette not found");
1056
1116
  }
1057
1117
 
1058
1118
  this.inflateData(data);
1059
- var leftOverLength = length - data.length;
1119
+ let leftOverLength = length - data.length;
1060
1120
 
1061
1121
  if (leftOverLength > 0) {
1062
1122
  this._handleIDAT(leftOverLength);
1063
- }
1064
- else {
1123
+ } else {
1065
1124
  this._handleChunkEnd();
1066
1125
  }
1067
1126
  };
1068
1127
 
1069
- Parser.prototype._handleIEND = function(length) {
1128
+ Parser.prototype._handleIEND = function (length) {
1070
1129
  this.read(length, this._parseIEND.bind(this));
1071
1130
  };
1072
- Parser.prototype._parseIEND = function(data) {
1073
-
1131
+ Parser.prototype._parseIEND = function (data) {
1074
1132
  this._crc.write(data);
1075
1133
 
1076
1134
  this._hasIEND = true;
@@ -1082,18 +1140,18 @@ Parser.prototype._parseIEND = function(data) {
1082
1140
  };
1083
1141
  });
1084
1142
 
1085
- var pixelBppMapper = [
1143
+ let pixelBppMapper = [
1086
1144
  // 0 - dummy entry
1087
- function() {},
1145
+ function () {},
1088
1146
 
1089
1147
  // 1 - L
1090
1148
  // 0: 0, 1: 0, 2: 0, 3: 0xff
1091
- function(pxData, data, pxPos, rawPos) {
1149
+ function (pxData, data, pxPos, rawPos) {
1092
1150
  if (rawPos === data.length) {
1093
- throw new Error('Ran out of data');
1151
+ throw new Error("Ran out of data");
1094
1152
  }
1095
1153
 
1096
- var pixel = data[rawPos];
1154
+ let pixel = data[rawPos];
1097
1155
  pxData[pxPos] = pixel;
1098
1156
  pxData[pxPos + 1] = pixel;
1099
1157
  pxData[pxPos + 2] = pixel;
@@ -1102,12 +1160,12 @@ var pixelBppMapper = [
1102
1160
 
1103
1161
  // 2 - LA
1104
1162
  // 0: 0, 1: 0, 2: 0, 3: 1
1105
- function(pxData, data, pxPos, rawPos) {
1163
+ function (pxData, data, pxPos, rawPos) {
1106
1164
  if (rawPos + 1 >= data.length) {
1107
- throw new Error('Ran out of data');
1165
+ throw new Error("Ran out of data");
1108
1166
  }
1109
1167
 
1110
- var pixel = data[rawPos];
1168
+ let pixel = data[rawPos];
1111
1169
  pxData[pxPos] = pixel;
1112
1170
  pxData[pxPos + 1] = pixel;
1113
1171
  pxData[pxPos + 2] = pixel;
@@ -1116,9 +1174,9 @@ var pixelBppMapper = [
1116
1174
 
1117
1175
  // 3 - RGB
1118
1176
  // 0: 0, 1: 1, 2: 2, 3: 0xff
1119
- function(pxData, data, pxPos, rawPos) {
1177
+ function (pxData, data, pxPos, rawPos) {
1120
1178
  if (rawPos + 2 >= data.length) {
1121
- throw new Error('Ran out of data');
1179
+ throw new Error("Ran out of data");
1122
1180
  }
1123
1181
 
1124
1182
  pxData[pxPos] = data[rawPos];
@@ -1129,26 +1187,26 @@ var pixelBppMapper = [
1129
1187
 
1130
1188
  // 4 - RGBA
1131
1189
  // 0: 0, 1: 1, 2: 2, 3: 3
1132
- function(pxData, data, pxPos, rawPos) {
1190
+ function (pxData, data, pxPos, rawPos) {
1133
1191
  if (rawPos + 3 >= data.length) {
1134
- throw new Error('Ran out of data');
1192
+ throw new Error("Ran out of data");
1135
1193
  }
1136
1194
 
1137
1195
  pxData[pxPos] = data[rawPos];
1138
1196
  pxData[pxPos + 1] = data[rawPos + 1];
1139
1197
  pxData[pxPos + 2] = data[rawPos + 2];
1140
1198
  pxData[pxPos + 3] = data[rawPos + 3];
1141
- }
1199
+ },
1142
1200
  ];
1143
1201
 
1144
- var pixelBppCustomMapper = [
1202
+ let pixelBppCustomMapper = [
1145
1203
  // 0 - dummy entry
1146
- function() {},
1204
+ function () {},
1147
1205
 
1148
1206
  // 1 - L
1149
1207
  // 0: 0, 1: 0, 2: 0, 3: 0xff
1150
- function(pxData, pixelData, pxPos, maxBit) {
1151
- var pixel = pixelData[0];
1208
+ function (pxData, pixelData, pxPos, maxBit) {
1209
+ let pixel = pixelData[0];
1152
1210
  pxData[pxPos] = pixel;
1153
1211
  pxData[pxPos + 1] = pixel;
1154
1212
  pxData[pxPos + 2] = pixel;
@@ -1157,8 +1215,8 @@ var pixelBppCustomMapper = [
1157
1215
 
1158
1216
  // 2 - LA
1159
1217
  // 0: 0, 1: 0, 2: 0, 3: 1
1160
- function(pxData, pixelData, pxPos) {
1161
- var pixel = pixelData[0];
1218
+ function (pxData, pixelData, pxPos) {
1219
+ let pixel = pixelData[0];
1162
1220
  pxData[pxPos] = pixel;
1163
1221
  pxData[pxPos + 1] = pixel;
1164
1222
  pxData[pxPos + 2] = pixel;
@@ -1167,7 +1225,7 @@ var pixelBppCustomMapper = [
1167
1225
 
1168
1226
  // 3 - RGB
1169
1227
  // 0: 0, 1: 1, 2: 2, 3: 0xff
1170
- function(pxData, pixelData, pxPos, maxBit) {
1228
+ function (pxData, pixelData, pxPos, maxBit) {
1171
1229
  pxData[pxPos] = pixelData[0];
1172
1230
  pxData[pxPos + 1] = pixelData[1];
1173
1231
  pxData[pxPos + 2] = pixelData[2];
@@ -1176,33 +1234,32 @@ var pixelBppCustomMapper = [
1176
1234
 
1177
1235
  // 4 - RGBA
1178
1236
  // 0: 0, 1: 1, 2: 2, 3: 3
1179
- function(pxData, pixelData, pxPos) {
1237
+ function (pxData, pixelData, pxPos) {
1180
1238
  pxData[pxPos] = pixelData[0];
1181
1239
  pxData[pxPos + 1] = pixelData[1];
1182
1240
  pxData[pxPos + 2] = pixelData[2];
1183
1241
  pxData[pxPos + 3] = pixelData[3];
1184
- }
1242
+ },
1185
1243
  ];
1186
1244
 
1187
1245
  function bitRetriever(data, depth) {
1188
-
1189
- var leftOver = [];
1190
- var i = 0;
1246
+ let leftOver = [];
1247
+ let i = 0;
1191
1248
 
1192
1249
  function split() {
1193
1250
  if (i === data.length) {
1194
- throw new Error('Ran out of data');
1251
+ throw new Error("Ran out of data");
1195
1252
  }
1196
- var byte = data[i];
1253
+ let byte = data[i];
1197
1254
  i++;
1198
- var byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
1255
+ let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
1199
1256
  switch (depth) {
1200
1257
  default:
1201
- throw new Error('unrecognised depth');
1258
+ throw new Error("unrecognised depth");
1202
1259
  case 16:
1203
1260
  byte2 = data[i];
1204
1261
  i++;
1205
- leftOver.push(((byte << 8) + byte2));
1262
+ leftOver.push((byte << 8) + byte2);
1206
1263
  break;
1207
1264
  case 4:
1208
1265
  byte2 = byte & 0x0f;
@@ -1211,52 +1268,53 @@ function bitRetriever(data, depth) {
1211
1268
  break;
1212
1269
  case 2:
1213
1270
  byte4 = byte & 3;
1214
- byte3 = byte >> 2 & 3;
1215
- byte2 = byte >> 4 & 3;
1216
- byte1 = byte >> 6 & 3;
1271
+ byte3 = (byte >> 2) & 3;
1272
+ byte2 = (byte >> 4) & 3;
1273
+ byte1 = (byte >> 6) & 3;
1217
1274
  leftOver.push(byte1, byte2, byte3, byte4);
1218
1275
  break;
1219
1276
  case 1:
1220
1277
  byte8 = byte & 1;
1221
- byte7 = byte >> 1 & 1;
1222
- byte6 = byte >> 2 & 1;
1223
- byte5 = byte >> 3 & 1;
1224
- byte4 = byte >> 4 & 1;
1225
- byte3 = byte >> 5 & 1;
1226
- byte2 = byte >> 6 & 1;
1227
- byte1 = byte >> 7 & 1;
1278
+ byte7 = (byte >> 1) & 1;
1279
+ byte6 = (byte >> 2) & 1;
1280
+ byte5 = (byte >> 3) & 1;
1281
+ byte4 = (byte >> 4) & 1;
1282
+ byte3 = (byte >> 5) & 1;
1283
+ byte2 = (byte >> 6) & 1;
1284
+ byte1 = (byte >> 7) & 1;
1228
1285
  leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
1229
1286
  break;
1230
1287
  }
1231
1288
  }
1232
1289
 
1233
1290
  return {
1234
- get: function(count) {
1291
+ get: function (count) {
1235
1292
  while (leftOver.length < count) {
1236
1293
  split();
1237
1294
  }
1238
- var returner = leftOver.slice(0, count);
1295
+ let returner = leftOver.slice(0, count);
1239
1296
  leftOver = leftOver.slice(count);
1240
1297
  return returner;
1241
1298
  },
1242
- resetAfterLine: function() {
1299
+ resetAfterLine: function () {
1243
1300
  leftOver.length = 0;
1244
1301
  },
1245
- end: function() {
1302
+ end: function () {
1246
1303
  if (i !== data.length) {
1247
- throw new Error('extra data found');
1304
+ throw new Error("extra data found");
1248
1305
  }
1249
- }
1306
+ },
1250
1307
  };
1251
1308
  }
1252
1309
 
1253
- function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) { // eslint-disable-line max-params
1254
- var imageWidth = image.width;
1255
- var imageHeight = image.height;
1256
- var imagePass = image.index;
1257
- for (var y = 0; y < imageHeight; y++) {
1258
- for (var x = 0; x < imageWidth; x++) {
1259
- var pxPos = getPxPos(x, y, imagePass);
1310
+ function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
1311
+ // eslint-disable-line max-params
1312
+ let imageWidth = image.width;
1313
+ let imageHeight = image.height;
1314
+ let imagePass = image.index;
1315
+ for (let y = 0; y < imageHeight; y++) {
1316
+ for (let x = 0; x < imageWidth; x++) {
1317
+ let pxPos = getPxPos(x, y, imagePass);
1260
1318
  pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
1261
1319
  rawPos += bpp; //eslint-disable-line no-param-reassign
1262
1320
  }
@@ -1264,71 +1322,82 @@ function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) { // eslint-di
1264
1322
  return rawPos;
1265
1323
  }
1266
1324
 
1267
- function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) { // eslint-disable-line max-params
1268
- var imageWidth = image.width;
1269
- var imageHeight = image.height;
1270
- var imagePass = image.index;
1271
- for (var y = 0; y < imageHeight; y++) {
1272
- for (var x = 0; x < imageWidth; x++) {
1273
- var pixelData = bits.get(bpp);
1274
- var pxPos = getPxPos(x, y, imagePass);
1325
+ function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
1326
+ // eslint-disable-line max-params
1327
+ let imageWidth = image.width;
1328
+ let imageHeight = image.height;
1329
+ let imagePass = image.index;
1330
+ for (let y = 0; y < imageHeight; y++) {
1331
+ for (let x = 0; x < imageWidth; x++) {
1332
+ let pixelData = bits.get(bpp);
1333
+ let pxPos = getPxPos(x, y, imagePass);
1275
1334
  pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
1276
1335
  }
1277
1336
  bits.resetAfterLine();
1278
1337
  }
1279
1338
  }
1280
1339
 
1281
- var dataToBitMap = function(data, bitmapInfo) {
1282
-
1283
- var width = bitmapInfo.width;
1284
- var height = bitmapInfo.height;
1285
- var depth = bitmapInfo.depth;
1286
- var bpp = bitmapInfo.bpp;
1287
- var interlace$1 = bitmapInfo.interlace;
1340
+ var dataToBitMap = function (data, bitmapInfo) {
1341
+ let width = bitmapInfo.width;
1342
+ let height = bitmapInfo.height;
1343
+ let depth = bitmapInfo.depth;
1344
+ let bpp = bitmapInfo.bpp;
1345
+ let interlace$1 = bitmapInfo.interlace;
1346
+ let bits;
1288
1347
 
1289
1348
  if (depth !== 8) {
1290
- var bits = bitRetriever(data, depth);
1349
+ bits = bitRetriever(data, depth);
1291
1350
  }
1292
- var pxData;
1351
+ let pxData;
1293
1352
  if (depth <= 8) {
1294
- pxData = new Buffer(width * height * 4);
1295
- }
1296
- else {
1353
+ pxData = Buffer.alloc(width * height * 4);
1354
+ } else {
1297
1355
  pxData = new Uint16Array(width * height * 4);
1298
1356
  }
1299
- var maxBit = Math.pow(2, depth) - 1;
1300
- var rawPos = 0;
1301
- var images;
1302
- var getPxPos;
1357
+ let maxBit = Math.pow(2, depth) - 1;
1358
+ let rawPos = 0;
1359
+ let images;
1360
+ let getPxPos;
1303
1361
 
1304
1362
  if (interlace$1) {
1305
1363
  images = interlace.getImagePasses(width, height);
1306
1364
  getPxPos = interlace.getInterlaceIterator(width, height);
1307
- }
1308
- else {
1309
- var nonInterlacedPxPos = 0;
1310
- getPxPos = function() {
1311
- var returner = nonInterlacedPxPos;
1365
+ } else {
1366
+ let nonInterlacedPxPos = 0;
1367
+ getPxPos = function () {
1368
+ let returner = nonInterlacedPxPos;
1312
1369
  nonInterlacedPxPos += 4;
1313
1370
  return returner;
1314
1371
  };
1315
1372
  images = [{ width: width, height: height }];
1316
1373
  }
1317
1374
 
1318
- for (var imageIndex = 0; imageIndex < images.length; imageIndex++) {
1375
+ for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
1319
1376
  if (depth === 8) {
1320
- rawPos = mapImage8Bit(images[imageIndex], pxData, getPxPos, bpp, data, rawPos);
1321
- }
1322
- else {
1323
- mapImageCustomBit(images[imageIndex], pxData, getPxPos, bpp, bits, maxBit);
1377
+ rawPos = mapImage8Bit(
1378
+ images[imageIndex],
1379
+ pxData,
1380
+ getPxPos,
1381
+ bpp,
1382
+ data,
1383
+ rawPos
1384
+ );
1385
+ } else {
1386
+ mapImageCustomBit(
1387
+ images[imageIndex],
1388
+ pxData,
1389
+ getPxPos,
1390
+ bpp,
1391
+ bits,
1392
+ maxBit
1393
+ );
1324
1394
  }
1325
1395
  }
1326
1396
  if (depth === 8) {
1327
1397
  if (rawPos !== data.length) {
1328
- throw new Error('extra data found');
1398
+ throw new Error("extra data found");
1329
1399
  }
1330
- }
1331
- else {
1400
+ } else {
1332
1401
  bits.end();
1333
1402
  }
1334
1403
 
@@ -1340,17 +1409,17 @@ var bitmapper = {
1340
1409
  };
1341
1410
 
1342
1411
  function dePalette(indata, outdata, width, height, palette) {
1343
- var pxPos = 0;
1412
+ let pxPos = 0;
1344
1413
  // use values from palette
1345
- for (var y = 0; y < height; y++) {
1346
- for (var x = 0; x < width; x++) {
1347
- var color = palette[indata[pxPos]];
1414
+ for (let y = 0; y < height; y++) {
1415
+ for (let x = 0; x < width; x++) {
1416
+ let color = palette[indata[pxPos]];
1348
1417
 
1349
1418
  if (!color) {
1350
- throw new Error('index ' + indata[pxPos] + ' not in palette');
1419
+ throw new Error("index " + indata[pxPos] + " not in palette");
1351
1420
  }
1352
1421
 
1353
- for (var i = 0; i < 4; i++) {
1422
+ for (let i = 0; i < 4; i++) {
1354
1423
  outdata[pxPos + i] = color[i];
1355
1424
  }
1356
1425
  pxPos += 4;
@@ -1359,21 +1428,24 @@ function dePalette(indata, outdata, width, height, palette) {
1359
1428
  }
1360
1429
 
1361
1430
  function replaceTransparentColor(indata, outdata, width, height, transColor) {
1362
- var pxPos = 0;
1363
- for (var y = 0; y < height; y++) {
1364
- for (var x = 0; x < width; x++) {
1365
- var makeTrans = false;
1431
+ let pxPos = 0;
1432
+ for (let y = 0; y < height; y++) {
1433
+ for (let x = 0; x < width; x++) {
1434
+ let makeTrans = false;
1366
1435
 
1367
1436
  if (transColor.length === 1) {
1368
1437
  if (transColor[0] === indata[pxPos]) {
1369
1438
  makeTrans = true;
1370
1439
  }
1371
- }
1372
- else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
1440
+ } else if (
1441
+ transColor[0] === indata[pxPos] &&
1442
+ transColor[1] === indata[pxPos + 1] &&
1443
+ transColor[2] === indata[pxPos + 2]
1444
+ ) {
1373
1445
  makeTrans = true;
1374
1446
  }
1375
1447
  if (makeTrans) {
1376
- for (var i = 0; i < 4; i++) {
1448
+ for (let i = 0; i < 4; i++) {
1377
1449
  outdata[pxPos + i] = 0;
1378
1450
  }
1379
1451
  }
@@ -1383,43 +1455,44 @@ function replaceTransparentColor(indata, outdata, width, height, transColor) {
1383
1455
  }
1384
1456
 
1385
1457
  function scaleDepth(indata, outdata, width, height, depth) {
1386
- var maxOutSample = 255;
1387
- var maxInSample = Math.pow(2, depth) - 1;
1388
- var pxPos = 0;
1389
-
1390
- for (var y = 0; y < height; y++) {
1391
- for (var x = 0; x < width; x++) {
1392
- for (var i = 0; i < 4; i++) {
1393
- outdata[pxPos + i] = Math.floor((indata[pxPos + i] * maxOutSample) / maxInSample + 0.5);
1458
+ let maxOutSample = 255;
1459
+ let maxInSample = Math.pow(2, depth) - 1;
1460
+ let pxPos = 0;
1461
+
1462
+ for (let y = 0; y < height; y++) {
1463
+ for (let x = 0; x < width; x++) {
1464
+ for (let i = 0; i < 4; i++) {
1465
+ outdata[pxPos + i] = Math.floor(
1466
+ (indata[pxPos + i] * maxOutSample) / maxInSample + 0.5
1467
+ );
1394
1468
  }
1395
1469
  pxPos += 4;
1396
1470
  }
1397
1471
  }
1398
1472
  }
1399
1473
 
1400
- var formatNormaliser = function(indata, imageData) {
1401
-
1402
- var depth = imageData.depth;
1403
- var width = imageData.width;
1404
- var height = imageData.height;
1405
- var colorType = imageData.colorType;
1406
- var transColor = imageData.transColor;
1407
- var palette = imageData.palette;
1474
+ var formatNormaliser = function (indata, imageData, skipRescale = false) {
1475
+ let depth = imageData.depth;
1476
+ let width = imageData.width;
1477
+ let height = imageData.height;
1478
+ let colorType = imageData.colorType;
1479
+ let transColor = imageData.transColor;
1480
+ let palette = imageData.palette;
1408
1481
 
1409
- var outdata = indata; // only different for 16 bits
1482
+ let outdata = indata; // only different for 16 bits
1410
1483
 
1411
- if (colorType === 3) { // paletted
1484
+ if (colorType === 3) {
1485
+ // paletted
1412
1486
  dePalette(indata, outdata, width, height, palette);
1413
- }
1414
- else {
1487
+ } else {
1415
1488
  if (transColor) {
1416
1489
  replaceTransparentColor(indata, outdata, width, height, transColor);
1417
1490
  }
1418
1491
  // if it needs scaling
1419
- if (depth !== 8) {
1492
+ if (depth !== 8 && !skipRescale) {
1420
1493
  // if we need to change the buffer size
1421
1494
  if (depth === 16) {
1422
- outdata = new Buffer(width * height * 4);
1495
+ outdata = Buffer.alloc(width * height * 4);
1423
1496
  }
1424
1497
  scaleDepth(indata, outdata, width, height, depth);
1425
1498
  }
@@ -1437,32 +1510,30 @@ var parserAsync = createCommonjsModule(function (module) {
1437
1510
 
1438
1511
 
1439
1512
 
1440
- var ParserAsync = module.exports = function(options) {
1513
+ let ParserAsync = (module.exports = function (options) {
1441
1514
  chunkstream.call(this);
1442
1515
 
1443
1516
  this._parser = new parser(options, {
1444
1517
  read: this.read.bind(this),
1445
1518
  error: this._handleError.bind(this),
1446
1519
  metadata: this._handleMetaData.bind(this),
1447
- gamma: this.emit.bind(this, 'gamma'),
1520
+ gamma: this.emit.bind(this, "gamma"),
1448
1521
  palette: this._handlePalette.bind(this),
1449
1522
  transColor: this._handleTransColor.bind(this),
1450
1523
  finished: this._finished.bind(this),
1451
1524
  inflateData: this._inflateData.bind(this),
1452
1525
  simpleTransparency: this._simpleTransparency.bind(this),
1453
- headersFinished: this._headersFinished.bind(this)
1526
+ headersFinished: this._headersFinished.bind(this),
1454
1527
  });
1455
1528
  this._options = options;
1456
1529
  this.writable = true;
1457
1530
 
1458
1531
  this._parser.start();
1459
- };
1532
+ });
1460
1533
  util__default['default'].inherits(ParserAsync, chunkstream);
1461
1534
 
1462
-
1463
- ParserAsync.prototype._handleError = function(err) {
1464
-
1465
- this.emit('error', err);
1535
+ ParserAsync.prototype._handleError = function (err) {
1536
+ this.emit("error", err);
1466
1537
 
1467
1538
  this.writable = false;
1468
1539
 
@@ -1477,42 +1548,47 @@ ParserAsync.prototype._handleError = function(err) {
1477
1548
  // For backward compatibility with Node 7 and below.
1478
1549
  // Suppress errors due to _inflate calling write() even after
1479
1550
  // it's destroy()'ed.
1480
- this._filter.on('error', function() {});
1551
+ this._filter.on("error", function () {});
1481
1552
  }
1482
1553
 
1483
1554
  this.errord = true;
1484
1555
  };
1485
1556
 
1486
- ParserAsync.prototype._inflateData = function(data) {
1557
+ ParserAsync.prototype._inflateData = function (data) {
1487
1558
  if (!this._inflate) {
1488
1559
  if (this._bitmapInfo.interlace) {
1489
1560
  this._inflate = zlib__default['default'].createInflate();
1490
1561
 
1491
- this._inflate.on('error', this.emit.bind(this, 'error'));
1492
- this._filter.on('complete', this._complete.bind(this));
1562
+ this._inflate.on("error", this.emit.bind(this, "error"));
1563
+ this._filter.on("complete", this._complete.bind(this));
1493
1564
 
1494
1565
  this._inflate.pipe(this._filter);
1495
- }
1496
- else {
1497
- var rowSize = ((this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7) >> 3) + 1;
1498
- var imageSize = rowSize * this._bitmapInfo.height;
1499
- var chunkSize = Math.max(imageSize, zlib__default['default'].Z_MIN_CHUNK);
1566
+ } else {
1567
+ let rowSize =
1568
+ ((this._bitmapInfo.width *
1569
+ this._bitmapInfo.bpp *
1570
+ this._bitmapInfo.depth +
1571
+ 7) >>
1572
+ 3) +
1573
+ 1;
1574
+ let imageSize = rowSize * this._bitmapInfo.height;
1575
+ let chunkSize = Math.max(imageSize, zlib__default['default'].Z_MIN_CHUNK);
1500
1576
 
1501
1577
  this._inflate = zlib__default['default'].createInflate({ chunkSize: chunkSize });
1502
- var leftToInflate = imageSize;
1578
+ let leftToInflate = imageSize;
1503
1579
 
1504
- var emitError = this.emit.bind(this, 'error');
1505
- this._inflate.on('error', function(err) {
1580
+ let emitError = this.emit.bind(this, "error");
1581
+ this._inflate.on("error", function (err) {
1506
1582
  if (!leftToInflate) {
1507
1583
  return;
1508
1584
  }
1509
1585
 
1510
1586
  emitError(err);
1511
1587
  });
1512
- this._filter.on('complete', this._complete.bind(this));
1588
+ this._filter.on("complete", this._complete.bind(this));
1513
1589
 
1514
- var filterWrite = this._filter.write.bind(this._filter);
1515
- this._inflate.on('data', function(chunk) {
1590
+ let filterWrite = this._filter.write.bind(this._filter);
1591
+ this._inflate.on("data", function (chunk) {
1516
1592
  if (!leftToInflate) {
1517
1593
  return;
1518
1594
  }
@@ -1526,78 +1602,83 @@ ParserAsync.prototype._inflateData = function(data) {
1526
1602
  filterWrite(chunk);
1527
1603
  });
1528
1604
 
1529
- this._inflate.on('end', this._filter.end.bind(this._filter));
1605
+ this._inflate.on("end", this._filter.end.bind(this._filter));
1530
1606
  }
1531
1607
  }
1532
1608
  this._inflate.write(data);
1533
1609
  };
1534
1610
 
1535
- ParserAsync.prototype._handleMetaData = function(metaData) {
1611
+ ParserAsync.prototype._handleMetaData = function (metaData) {
1536
1612
  this._metaData = metaData;
1537
1613
  this._bitmapInfo = Object.create(metaData);
1538
1614
 
1539
1615
  this._filter = new filterParseAsync(this._bitmapInfo);
1540
1616
  };
1541
1617
 
1542
- ParserAsync.prototype._handleTransColor = function(transColor) {
1618
+ ParserAsync.prototype._handleTransColor = function (transColor) {
1543
1619
  this._bitmapInfo.transColor = transColor;
1544
1620
  };
1545
1621
 
1546
- ParserAsync.prototype._handlePalette = function(palette) {
1622
+ ParserAsync.prototype._handlePalette = function (palette) {
1547
1623
  this._bitmapInfo.palette = palette;
1548
1624
  };
1549
1625
 
1550
- ParserAsync.prototype._simpleTransparency = function() {
1626
+ ParserAsync.prototype._simpleTransparency = function () {
1551
1627
  this._metaData.alpha = true;
1552
1628
  };
1553
1629
 
1554
- ParserAsync.prototype._headersFinished = function() {
1630
+ ParserAsync.prototype._headersFinished = function () {
1555
1631
  // Up until this point, we don't know if we have a tRNS chunk (alpha)
1556
1632
  // so we can't emit metadata any earlier
1557
- this.emit('metadata', this._metaData);
1633
+ this.emit("metadata", this._metaData);
1558
1634
  };
1559
1635
 
1560
- ParserAsync.prototype._finished = function() {
1636
+ ParserAsync.prototype._finished = function () {
1561
1637
  if (this.errord) {
1562
1638
  return;
1563
1639
  }
1564
1640
 
1565
1641
  if (!this._inflate) {
1566
- this.emit('error', 'No Inflate block');
1567
- }
1568
- else {
1642
+ this.emit("error", "No Inflate block");
1643
+ } else {
1569
1644
  // no more data to inflate
1570
1645
  this._inflate.end();
1571
1646
  }
1572
- this.destroySoon();
1573
1647
  };
1574
1648
 
1575
- ParserAsync.prototype._complete = function(filteredData) {
1576
-
1649
+ ParserAsync.prototype._complete = function (filteredData) {
1577
1650
  if (this.errord) {
1578
1651
  return;
1579
1652
  }
1580
1653
 
1654
+ let normalisedBitmapData;
1655
+
1581
1656
  try {
1582
- var bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
1657
+ let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
1583
1658
 
1584
- var normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo);
1659
+ normalisedBitmapData = formatNormaliser(
1660
+ bitmapData,
1661
+ this._bitmapInfo,
1662
+ this._options.skipRescale
1663
+ );
1585
1664
  bitmapData = null;
1586
- }
1587
- catch (ex) {
1665
+ } catch (ex) {
1588
1666
  this._handleError(ex);
1589
1667
  return;
1590
1668
  }
1591
1669
 
1592
- this.emit('parsed', normalisedBitmapData);
1670
+ this.emit("parsed", normalisedBitmapData);
1593
1671
  };
1594
1672
  });
1595
1673
 
1596
- var bitpacker = function(dataIn, width, height, options) {
1597
- var outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(options.colorType) !== -1;
1674
+ var bitpacker = function (dataIn, width, height, options) {
1675
+ let outHasAlpha =
1676
+ [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(
1677
+ options.colorType
1678
+ ) !== -1;
1598
1679
  if (options.colorType === options.inputColorType) {
1599
- var bigEndian = (function() {
1600
- var buffer = new ArrayBuffer(2);
1680
+ let bigEndian = (function () {
1681
+ let buffer = new ArrayBuffer(2);
1601
1682
  new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
1602
1683
  // Int16Array uses the platform's endianness.
1603
1684
  return new Int16Array(buffer)[0] !== 256;
@@ -1609,24 +1690,24 @@ var bitpacker = function(dataIn, width, height, options) {
1609
1690
  }
1610
1691
 
1611
1692
  // map to a UInt16 array if data is 16bit, fix endianness below
1612
- var data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
1693
+ let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
1613
1694
 
1614
- var maxValue = 255;
1615
- var inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
1695
+ let maxValue = 255;
1696
+ let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
1616
1697
  if (inBpp === 4 && !options.inputHasAlpha) {
1617
1698
  inBpp = 3;
1618
1699
  }
1619
- var outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
1700
+ let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
1620
1701
  if (options.bitDepth === 16) {
1621
1702
  maxValue = 65535;
1622
1703
  outBpp *= 2;
1623
1704
  }
1624
- var outData = new Buffer(width * height * outBpp);
1705
+ let outData = Buffer.alloc(width * height * outBpp);
1625
1706
 
1626
- var inIndex = 0;
1627
- var outIndex = 0;
1707
+ let inIndex = 0;
1708
+ let outIndex = 0;
1628
1709
 
1629
- var bgColor = options.bgColor || {};
1710
+ let bgColor = options.bgColor || {};
1630
1711
  if (bgColor.red === undefined) {
1631
1712
  bgColor.red = maxValue;
1632
1713
  }
@@ -1638,10 +1719,10 @@ var bitpacker = function(dataIn, width, height, options) {
1638
1719
  }
1639
1720
 
1640
1721
  function getRGBA() {
1641
- var red;
1642
- var green;
1643
- var blue;
1644
- var alpha = maxValue;
1722
+ let red;
1723
+ let green;
1724
+ let blue;
1725
+ let alpha = maxValue;
1645
1726
  switch (options.inputColorType) {
1646
1727
  case constants.COLORTYPE_COLOR_ALPHA:
1647
1728
  alpha = data[inIndex + 3];
@@ -1666,23 +1747,36 @@ var bitpacker = function(dataIn, width, height, options) {
1666
1747
  blue = red;
1667
1748
  break;
1668
1749
  default:
1669
- throw new Error('input color type:' + options.inputColorType + ' is not supported at present');
1750
+ throw new Error(
1751
+ "input color type:" +
1752
+ options.inputColorType +
1753
+ " is not supported at present"
1754
+ );
1670
1755
  }
1671
1756
 
1672
1757
  if (options.inputHasAlpha) {
1673
1758
  if (!outHasAlpha) {
1674
1759
  alpha /= maxValue;
1675
- red = Math.min(Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0), maxValue);
1676
- green = Math.min(Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0), maxValue);
1677
- blue = Math.min(Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0), maxValue);
1760
+ red = Math.min(
1761
+ Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
1762
+ maxValue
1763
+ );
1764
+ green = Math.min(
1765
+ Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
1766
+ maxValue
1767
+ );
1768
+ blue = Math.min(
1769
+ Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
1770
+ maxValue
1771
+ );
1678
1772
  }
1679
1773
  }
1680
1774
  return { red: red, green: green, blue: blue, alpha: alpha };
1681
1775
  }
1682
1776
 
1683
- for (var y = 0; y < height; y++) {
1684
- for (var x = 0; x < width; x++) {
1685
- var rgba = getRGBA();
1777
+ for (let y = 0; y < height; y++) {
1778
+ for (let x = 0; x < width; x++) {
1779
+ let rgba = getRGBA();
1686
1780
 
1687
1781
  switch (options.colorType) {
1688
1782
  case constants.COLORTYPE_COLOR_ALPHA:
@@ -1694,8 +1788,7 @@ var bitpacker = function(dataIn, width, height, options) {
1694
1788
  if (outHasAlpha) {
1695
1789
  outData[outIndex + 3] = rgba.alpha;
1696
1790
  }
1697
- }
1698
- else {
1791
+ } else {
1699
1792
  outData.writeUInt16BE(rgba.red, outIndex);
1700
1793
  outData.writeUInt16BE(rgba.green, outIndex + 2);
1701
1794
  outData.writeUInt16BE(rgba.blue, outIndex + 4);
@@ -1705,24 +1798,24 @@ var bitpacker = function(dataIn, width, height, options) {
1705
1798
  }
1706
1799
  break;
1707
1800
  case constants.COLORTYPE_ALPHA:
1708
- case constants.COLORTYPE_GRAYSCALE:
1801
+ case constants.COLORTYPE_GRAYSCALE: {
1709
1802
  // Convert to grayscale and alpha
1710
- var grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
1803
+ let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
1711
1804
  if (options.bitDepth === 8) {
1712
1805
  outData[outIndex] = grayscale;
1713
1806
  if (outHasAlpha) {
1714
1807
  outData[outIndex + 1] = rgba.alpha;
1715
1808
  }
1716
- }
1717
- else {
1809
+ } else {
1718
1810
  outData.writeUInt16BE(grayscale, outIndex);
1719
1811
  if (outHasAlpha) {
1720
1812
  outData.writeUInt16BE(rgba.alpha, outIndex + 2);
1721
1813
  }
1722
1814
  }
1723
1815
  break;
1816
+ }
1724
1817
  default:
1725
- throw new Error('unrecognised color Type ' + options.colorType);
1818
+ throw new Error("unrecognised color Type " + options.colorType);
1726
1819
  }
1727
1820
 
1728
1821
  inIndex += inBpp;
@@ -1734,41 +1827,35 @@ var bitpacker = function(dataIn, width, height, options) {
1734
1827
  };
1735
1828
 
1736
1829
  function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
1737
-
1738
- for (var x = 0; x < byteWidth; x++) {
1830
+ for (let x = 0; x < byteWidth; x++) {
1739
1831
  rawData[rawPos + x] = pxData[pxPos + x];
1740
1832
  }
1741
1833
  }
1742
1834
 
1743
1835
  function filterSumNone(pxData, pxPos, byteWidth) {
1836
+ let sum = 0;
1837
+ let length = pxPos + byteWidth;
1744
1838
 
1745
- var sum = 0;
1746
- var length = pxPos + byteWidth;
1747
-
1748
- for (var i = pxPos; i < length; i++) {
1839
+ for (let i = pxPos; i < length; i++) {
1749
1840
  sum += Math.abs(pxData[i]);
1750
1841
  }
1751
1842
  return sum;
1752
1843
  }
1753
1844
 
1754
1845
  function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1755
-
1756
- for (var x = 0; x < byteWidth; x++) {
1757
-
1758
- var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1759
- var val = pxData[pxPos + x] - left;
1846
+ for (let x = 0; x < byteWidth; x++) {
1847
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1848
+ let val = pxData[pxPos + x] - left;
1760
1849
 
1761
1850
  rawData[rawPos + x] = val;
1762
1851
  }
1763
1852
  }
1764
1853
 
1765
1854
  function filterSumSub(pxData, pxPos, byteWidth, bpp) {
1766
-
1767
- var sum = 0;
1768
- for (var x = 0; x < byteWidth; x++) {
1769
-
1770
- var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1771
- var val = pxData[pxPos + x] - left;
1855
+ let sum = 0;
1856
+ for (let x = 0; x < byteWidth; x++) {
1857
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1858
+ let val = pxData[pxPos + x] - left;
1772
1859
 
1773
1860
  sum += Math.abs(val);
1774
1861
  }
@@ -1777,24 +1864,20 @@ function filterSumSub(pxData, pxPos, byteWidth, bpp) {
1777
1864
  }
1778
1865
 
1779
1866
  function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
1780
-
1781
- for (var x = 0; x < byteWidth; x++) {
1782
-
1783
- var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1784
- var val = pxData[pxPos + x] - up;
1867
+ for (let x = 0; x < byteWidth; x++) {
1868
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1869
+ let val = pxData[pxPos + x] - up;
1785
1870
 
1786
1871
  rawData[rawPos + x] = val;
1787
1872
  }
1788
1873
  }
1789
1874
 
1790
1875
  function filterSumUp(pxData, pxPos, byteWidth) {
1791
-
1792
- var sum = 0;
1793
- var length = pxPos + byteWidth;
1794
- for (var x = pxPos; x < length; x++) {
1795
-
1796
- var up = pxPos > 0 ? pxData[x - byteWidth] : 0;
1797
- var val = pxData[x] - up;
1876
+ let sum = 0;
1877
+ let length = pxPos + byteWidth;
1878
+ for (let x = pxPos; x < length; x++) {
1879
+ let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
1880
+ let val = pxData[x] - up;
1798
1881
 
1799
1882
  sum += Math.abs(val);
1800
1883
  }
@@ -1803,25 +1886,21 @@ function filterSumUp(pxData, pxPos, byteWidth) {
1803
1886
  }
1804
1887
 
1805
1888
  function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1806
-
1807
- for (var x = 0; x < byteWidth; x++) {
1808
-
1809
- var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1810
- var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1811
- var val = pxData[pxPos + x] - ((left + up) >> 1);
1889
+ for (let x = 0; x < byteWidth; x++) {
1890
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1891
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1892
+ let val = pxData[pxPos + x] - ((left + up) >> 1);
1812
1893
 
1813
1894
  rawData[rawPos + x] = val;
1814
1895
  }
1815
1896
  }
1816
1897
 
1817
1898
  function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
1818
-
1819
- var sum = 0;
1820
- for (var x = 0; x < byteWidth; x++) {
1821
-
1822
- var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1823
- var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1824
- var val = pxData[pxPos + x] - ((left + up) >> 1);
1899
+ let sum = 0;
1900
+ for (let x = 0; x < byteWidth; x++) {
1901
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1902
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1903
+ let val = pxData[pxPos + x] - ((left + up) >> 1);
1825
1904
 
1826
1905
  sum += Math.abs(val);
1827
1906
  }
@@ -1830,26 +1909,25 @@ function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
1830
1909
  }
1831
1910
 
1832
1911
  function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1833
-
1834
- for (var x = 0; x < byteWidth; x++) {
1835
-
1836
- var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1837
- var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1838
- var upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1839
- var val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1912
+ for (let x = 0; x < byteWidth; x++) {
1913
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1914
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1915
+ let upleft =
1916
+ pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1917
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1840
1918
 
1841
1919
  rawData[rawPos + x] = val;
1842
1920
  }
1843
1921
  }
1844
1922
 
1845
1923
  function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
1846
- var sum = 0;
1847
- for (var x = 0; x < byteWidth; x++) {
1848
-
1849
- var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1850
- var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1851
- var upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1852
- var val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1924
+ let sum = 0;
1925
+ for (let x = 0; x < byteWidth; x++) {
1926
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1927
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1928
+ let upleft =
1929
+ pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1930
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1853
1931
 
1854
1932
  sum += Math.abs(val);
1855
1933
  }
@@ -1857,53 +1935,49 @@ function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
1857
1935
  return sum;
1858
1936
  }
1859
1937
 
1860
- var filters = {
1938
+ let filters = {
1861
1939
  0: filterNone,
1862
1940
  1: filterSub,
1863
1941
  2: filterUp,
1864
1942
  3: filterAvg,
1865
- 4: filterPaeth
1943
+ 4: filterPaeth,
1866
1944
  };
1867
1945
 
1868
- var filterSums = {
1946
+ let filterSums = {
1869
1947
  0: filterSumNone,
1870
1948
  1: filterSumSub,
1871
1949
  2: filterSumUp,
1872
1950
  3: filterSumAvg,
1873
- 4: filterSumPaeth
1951
+ 4: filterSumPaeth,
1874
1952
  };
1875
1953
 
1876
- var filterPack = function(pxData, width, height, options, bpp) {
1877
-
1878
- var filterTypes;
1879
- if (!('filterType' in options) || options.filterType === -1) {
1954
+ var filterPack = function (pxData, width, height, options, bpp) {
1955
+ let filterTypes;
1956
+ if (!("filterType" in options) || options.filterType === -1) {
1880
1957
  filterTypes = [0, 1, 2, 3, 4];
1881
- }
1882
- else if (typeof options.filterType === 'number') {
1958
+ } else if (typeof options.filterType === "number") {
1883
1959
  filterTypes = [options.filterType];
1884
- }
1885
- else {
1886
- throw new Error('unrecognised filter types');
1960
+ } else {
1961
+ throw new Error("unrecognised filter types");
1887
1962
  }
1888
1963
 
1889
1964
  if (options.bitDepth === 16) {
1890
1965
  bpp *= 2;
1891
1966
  }
1892
- var byteWidth = width * bpp;
1893
- var rawPos = 0;
1894
- var pxPos = 0;
1895
- var rawData = new Buffer((byteWidth + 1) * height);
1896
-
1897
- var sel = filterTypes[0];
1967
+ let byteWidth = width * bpp;
1968
+ let rawPos = 0;
1969
+ let pxPos = 0;
1970
+ let rawData = Buffer.alloc((byteWidth + 1) * height);
1898
1971
 
1899
- for (var y = 0; y < height; y++) {
1972
+ let sel = filterTypes[0];
1900
1973
 
1974
+ for (let y = 0; y < height; y++) {
1901
1975
  if (filterTypes.length > 1) {
1902
1976
  // find best filter for this line (with lowest sum of values)
1903
- var min = Infinity;
1977
+ let min = Infinity;
1904
1978
 
1905
- for (var i = 0; i < filterTypes.length; i++) {
1906
- var sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
1979
+ for (let i = 0; i < filterTypes.length; i++) {
1980
+ let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
1907
1981
  if (sum < min) {
1908
1982
  sel = filterTypes[i];
1909
1983
  min = sum;
@@ -1928,66 +2002,86 @@ var packer = createCommonjsModule(function (module) {
1928
2002
 
1929
2003
 
1930
2004
 
1931
- var Packer = module.exports = function(options) {
2005
+ let Packer = (module.exports = function (options) {
1932
2006
  this._options = options;
1933
2007
 
1934
2008
  options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
1935
- options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
1936
- options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
1937
- options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
2009
+ options.deflateLevel =
2010
+ options.deflateLevel != null ? options.deflateLevel : 9;
2011
+ options.deflateStrategy =
2012
+ options.deflateStrategy != null ? options.deflateStrategy : 3;
2013
+ options.inputHasAlpha =
2014
+ options.inputHasAlpha != null ? options.inputHasAlpha : true;
1938
2015
  options.deflateFactory = options.deflateFactory || zlib__default['default'].createDeflate;
1939
2016
  options.bitDepth = options.bitDepth || 8;
1940
2017
  // This is outputColorType
1941
- options.colorType = (typeof options.colorType === 'number') ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
1942
- options.inputColorType = (typeof options.inputColorType === 'number') ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
1943
-
1944
- if ([
1945
- constants.COLORTYPE_GRAYSCALE,
1946
- constants.COLORTYPE_COLOR,
1947
- constants.COLORTYPE_COLOR_ALPHA,
1948
- constants.COLORTYPE_ALPHA
1949
- ].indexOf(options.colorType) === -1) {
1950
- throw new Error('option color type:' + options.colorType + ' is not supported at present');
1951
- }
1952
- if ([
1953
- constants.COLORTYPE_GRAYSCALE,
1954
- constants.COLORTYPE_COLOR,
1955
- constants.COLORTYPE_COLOR_ALPHA,
1956
- constants.COLORTYPE_ALPHA
1957
- ].indexOf(options.inputColorType) === -1) {
1958
- throw new Error('option input color type:' + options.inputColorType + ' is not supported at present');
2018
+ options.colorType =
2019
+ typeof options.colorType === "number"
2020
+ ? options.colorType
2021
+ : constants.COLORTYPE_COLOR_ALPHA;
2022
+ options.inputColorType =
2023
+ typeof options.inputColorType === "number"
2024
+ ? options.inputColorType
2025
+ : constants.COLORTYPE_COLOR_ALPHA;
2026
+
2027
+ if (
2028
+ [
2029
+ constants.COLORTYPE_GRAYSCALE,
2030
+ constants.COLORTYPE_COLOR,
2031
+ constants.COLORTYPE_COLOR_ALPHA,
2032
+ constants.COLORTYPE_ALPHA,
2033
+ ].indexOf(options.colorType) === -1
2034
+ ) {
2035
+ throw new Error(
2036
+ "option color type:" + options.colorType + " is not supported at present"
2037
+ );
2038
+ }
2039
+ if (
2040
+ [
2041
+ constants.COLORTYPE_GRAYSCALE,
2042
+ constants.COLORTYPE_COLOR,
2043
+ constants.COLORTYPE_COLOR_ALPHA,
2044
+ constants.COLORTYPE_ALPHA,
2045
+ ].indexOf(options.inputColorType) === -1
2046
+ ) {
2047
+ throw new Error(
2048
+ "option input color type:" +
2049
+ options.inputColorType +
2050
+ " is not supported at present"
2051
+ );
1959
2052
  }
1960
2053
  if (options.bitDepth !== 8 && options.bitDepth !== 16) {
1961
- throw new Error('option bit depth:' + options.bitDepth + ' is not supported at present');
2054
+ throw new Error(
2055
+ "option bit depth:" + options.bitDepth + " is not supported at present"
2056
+ );
1962
2057
  }
1963
- };
2058
+ });
1964
2059
 
1965
- Packer.prototype.getDeflateOptions = function() {
2060
+ Packer.prototype.getDeflateOptions = function () {
1966
2061
  return {
1967
2062
  chunkSize: this._options.deflateChunkSize,
1968
2063
  level: this._options.deflateLevel,
1969
- strategy: this._options.deflateStrategy
2064
+ strategy: this._options.deflateStrategy,
1970
2065
  };
1971
2066
  };
1972
2067
 
1973
- Packer.prototype.createDeflate = function() {
2068
+ Packer.prototype.createDeflate = function () {
1974
2069
  return this._options.deflateFactory(this.getDeflateOptions());
1975
2070
  };
1976
2071
 
1977
- Packer.prototype.filterData = function(data, width, height) {
2072
+ Packer.prototype.filterData = function (data, width, height) {
1978
2073
  // convert to correct format for filtering (e.g. right bpp and bit depth)
1979
- var packedData = bitpacker(data, width, height, this._options);
2074
+ let packedData = bitpacker(data, width, height, this._options);
1980
2075
 
1981
2076
  // filter pixel data
1982
- var bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
1983
- var filteredData = filterPack(packedData, width, height, this._options, bpp);
2077
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
2078
+ let filteredData = filterPack(packedData, width, height, this._options, bpp);
1984
2079
  return filteredData;
1985
2080
  };
1986
2081
 
1987
- Packer.prototype._packChunk = function(type, data) {
1988
-
1989
- var len = (data ? data.length : 0);
1990
- var buf = new Buffer(len + 12);
2082
+ Packer.prototype._packChunk = function (type, data) {
2083
+ let len = data ? data.length : 0;
2084
+ let buf = Buffer.alloc(len + 12);
1991
2085
 
1992
2086
  buf.writeUInt32BE(len, 0);
1993
2087
  buf.writeUInt32BE(type, 4);
@@ -1996,19 +2090,21 @@ Packer.prototype._packChunk = function(type, data) {
1996
2090
  data.copy(buf, 8);
1997
2091
  }
1998
2092
 
1999
- buf.writeInt32BE(crc.crc32(buf.slice(4, buf.length - 4)), buf.length - 4);
2093
+ buf.writeInt32BE(
2094
+ crc.crc32(buf.slice(4, buf.length - 4)),
2095
+ buf.length - 4
2096
+ );
2000
2097
  return buf;
2001
2098
  };
2002
2099
 
2003
- Packer.prototype.packGAMA = function(gamma) {
2004
- var buf = new Buffer(4);
2100
+ Packer.prototype.packGAMA = function (gamma) {
2101
+ let buf = Buffer.alloc(4);
2005
2102
  buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
2006
2103
  return this._packChunk(constants.TYPE_gAMA, buf);
2007
2104
  };
2008
2105
 
2009
- Packer.prototype.packIHDR = function(width, height) {
2010
-
2011
- var buf = new Buffer(13);
2106
+ Packer.prototype.packIHDR = function (width, height) {
2107
+ let buf = Buffer.alloc(13);
2012
2108
  buf.writeUInt32BE(width, 0);
2013
2109
  buf.writeUInt32BE(height, 4);
2014
2110
  buf[8] = this._options.bitDepth; // Bit depth
@@ -2020,11 +2116,11 @@ Packer.prototype.packIHDR = function(width, height) {
2020
2116
  return this._packChunk(constants.TYPE_IHDR, buf);
2021
2117
  };
2022
2118
 
2023
- Packer.prototype.packIDAT = function(data) {
2119
+ Packer.prototype.packIDAT = function (data) {
2024
2120
  return this._packChunk(constants.TYPE_IDAT, data);
2025
2121
  };
2026
2122
 
2027
- Packer.prototype.packIEND = function() {
2123
+ Packer.prototype.packIEND = function () {
2028
2124
  return this._packChunk(constants.TYPE_IEND, null);
2029
2125
  };
2030
2126
  });
@@ -2036,41 +2132,46 @@ var packerAsync = createCommonjsModule(function (module) {
2036
2132
 
2037
2133
 
2038
2134
 
2039
- var PackerAsync = module.exports = function(opt) {
2135
+ let PackerAsync = (module.exports = function (opt) {
2040
2136
  Stream__default['default'].call(this);
2041
2137
 
2042
- var options = opt || {};
2138
+ let options = opt || {};
2043
2139
 
2044
2140
  this._packer = new packer(options);
2045
2141
  this._deflate = this._packer.createDeflate();
2046
2142
 
2047
2143
  this.readable = true;
2048
- };
2144
+ });
2049
2145
  util__default['default'].inherits(PackerAsync, Stream__default['default']);
2050
2146
 
2051
-
2052
- PackerAsync.prototype.pack = function(data, width, height, gamma) {
2147
+ PackerAsync.prototype.pack = function (data, width, height, gamma) {
2053
2148
  // Signature
2054
- this.emit('data', new Buffer(constants.PNG_SIGNATURE));
2055
- this.emit('data', this._packer.packIHDR(width, height));
2149
+ this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
2150
+ this.emit("data", this._packer.packIHDR(width, height));
2056
2151
 
2057
2152
  if (gamma) {
2058
- this.emit('data', this._packer.packGAMA(gamma));
2153
+ this.emit("data", this._packer.packGAMA(gamma));
2059
2154
  }
2060
2155
 
2061
- var filteredData = this._packer.filterData(data, width, height);
2156
+ let filteredData = this._packer.filterData(data, width, height);
2062
2157
 
2063
2158
  // compress it
2064
- this._deflate.on('error', this.emit.bind(this, 'error'));
2159
+ this._deflate.on("error", this.emit.bind(this, "error"));
2065
2160
 
2066
- this._deflate.on('data', function(compressedData) {
2067
- this.emit('data', this._packer.packIDAT(compressedData));
2068
- }.bind(this));
2161
+ this._deflate.on(
2162
+ "data",
2163
+ function (compressedData) {
2164
+ this.emit("data", this._packer.packIDAT(compressedData));
2165
+ }.bind(this)
2166
+ );
2069
2167
 
2070
- this._deflate.on('end', function() {
2071
- this.emit('data', this._packer.packIEND());
2072
- this.emit('end');
2073
- }.bind(this));
2168
+ this._deflate.on(
2169
+ "end",
2170
+ function () {
2171
+ this.emit("data", this._packer.packIEND());
2172
+ this.emit("end");
2173
+ }.bind(this)
2174
+ );
2074
2175
 
2075
2176
  this._deflate.end(filteredData);
2076
2177
  };
@@ -2078,11 +2179,11 @@ PackerAsync.prototype.pack = function(data, width, height, gamma) {
2078
2179
 
2079
2180
  var syncInflate = createCommonjsModule(function (module, exports) {
2080
2181
 
2081
- var assert = require$$0__default['default'].ok;
2182
+ let assert = require$$0__default['default'].ok;
2082
2183
 
2083
2184
 
2084
2185
 
2085
- var kMaxLength = require$$1__default['default'].kMaxLength;
2186
+ let kMaxLength = require$$1__default['default'].kMaxLength;
2086
2187
 
2087
2188
  function Inflate(opts) {
2088
2189
  if (!(this instanceof Inflate)) {
@@ -2122,23 +2223,23 @@ function _close(engine, callback) {
2122
2223
  engine._handle = null;
2123
2224
  }
2124
2225
 
2125
- Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
2126
- if (typeof asyncCb === 'function') {
2226
+ Inflate.prototype._processChunk = function (chunk, flushFlag, asyncCb) {
2227
+ if (typeof asyncCb === "function") {
2127
2228
  return zlib__default['default'].Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
2128
2229
  }
2129
2230
 
2130
- var self = this;
2231
+ let self = this;
2131
2232
 
2132
- var availInBefore = chunk && chunk.length;
2133
- var availOutBefore = this._chunkSize - this._offset;
2134
- var leftToInflate = this._maxLength;
2135
- var inOff = 0;
2233
+ let availInBefore = chunk && chunk.length;
2234
+ let availOutBefore = this._chunkSize - this._offset;
2235
+ let leftToInflate = this._maxLength;
2236
+ let inOff = 0;
2136
2237
 
2137
- var buffers = [];
2138
- var nread = 0;
2238
+ let buffers = [];
2239
+ let nread = 0;
2139
2240
 
2140
- var error;
2141
- this.on('error', function(err) {
2241
+ let error;
2242
+ this.on("error", function (err) {
2142
2243
  error = err;
2143
2244
  });
2144
2245
 
@@ -2147,11 +2248,11 @@ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
2147
2248
  return;
2148
2249
  }
2149
2250
 
2150
- var have = availOutBefore - availOutAfter;
2151
- assert(have >= 0, 'have should not go down');
2251
+ let have = availOutBefore - availOutAfter;
2252
+ assert(have >= 0, "have should not go down");
2152
2253
 
2153
2254
  if (have > 0) {
2154
- var out = self._buffer.slice(self._offset, self._offset + have);
2255
+ let out = self._buffer.slice(self._offset, self._offset + have);
2155
2256
  self._offset += have;
2156
2257
 
2157
2258
  if (out.length > leftToInflate) {
@@ -2174,7 +2275,7 @@ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
2174
2275
  }
2175
2276
 
2176
2277
  if (availOutAfter === 0) {
2177
- inOff += (availInBefore - availInAfter);
2278
+ inOff += availInBefore - availInAfter;
2178
2279
  availInBefore = availInAfter;
2179
2280
 
2180
2281
  return true;
@@ -2183,15 +2284,18 @@ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
2183
2284
  return false;
2184
2285
  }
2185
2286
 
2186
- assert(this._handle, 'zlib binding closed');
2287
+ assert(this._handle, "zlib binding closed");
2288
+ let res;
2187
2289
  do {
2188
- var res = this._handle.writeSync(flushFlag,
2290
+ res = this._handle.writeSync(
2291
+ flushFlag,
2189
2292
  chunk, // in
2190
2293
  inOff, // in_off
2191
2294
  availInBefore, // in_len
2192
2295
  this._buffer, // out
2193
2296
  this._offset, //out_off
2194
- availOutBefore); // out_len
2297
+ availOutBefore
2298
+ ); // out_len
2195
2299
  // Node 8 --> 9 compatibility check
2196
2300
  res = res || this._writeState;
2197
2301
  } while (!this._hadError && handleChunk(res[0], res[1]));
@@ -2202,10 +2306,14 @@ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
2202
2306
 
2203
2307
  if (nread >= kMaxLength) {
2204
2308
  _close(this);
2205
- throw new RangeError('Cannot create final Buffer. It would be larger than 0x' + kMaxLength.toString(16) + ' bytes');
2309
+ throw new RangeError(
2310
+ "Cannot create final Buffer. It would be larger than 0x" +
2311
+ kMaxLength.toString(16) +
2312
+ " bytes"
2313
+ );
2206
2314
  }
2207
2315
 
2208
- var buf = Buffer.concat(buffers, nread);
2316
+ let buf = Buffer.concat(buffers, nread);
2209
2317
  _close(this);
2210
2318
 
2211
2319
  return buf;
@@ -2214,14 +2322,14 @@ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
2214
2322
  util__default['default'].inherits(Inflate, zlib__default['default'].Inflate);
2215
2323
 
2216
2324
  function zlibBufferSync(engine, buffer) {
2217
- if (typeof buffer === 'string') {
2325
+ if (typeof buffer === "string") {
2218
2326
  buffer = Buffer.from(buffer);
2219
2327
  }
2220
2328
  if (!(buffer instanceof Buffer)) {
2221
- throw new TypeError('Not a string or buffer');
2329
+ throw new TypeError("Not a string or buffer");
2222
2330
  }
2223
2331
 
2224
- var flushFlag = engine._finishFlushFlag;
2332
+ let flushFlag = engine._finishFlushFlag;
2225
2333
  if (flushFlag == null) {
2226
2334
  flushFlag = zlib__default['default'].Z_FINISH;
2227
2335
  }
@@ -2241,68 +2349,60 @@ exports.inflateSync = inflateSync;
2241
2349
 
2242
2350
  var syncReader = createCommonjsModule(function (module) {
2243
2351
 
2244
- var SyncReader = module.exports = function(buffer) {
2245
-
2352
+ let SyncReader = (module.exports = function (buffer) {
2246
2353
  this._buffer = buffer;
2247
2354
  this._reads = [];
2248
- };
2249
-
2250
- SyncReader.prototype.read = function(length, callback) {
2355
+ });
2251
2356
 
2357
+ SyncReader.prototype.read = function (length, callback) {
2252
2358
  this._reads.push({
2253
2359
  length: Math.abs(length), // if length < 0 then at most this length
2254
2360
  allowLess: length < 0,
2255
- func: callback
2361
+ func: callback,
2256
2362
  });
2257
2363
  };
2258
2364
 
2259
- SyncReader.prototype.process = function() {
2260
-
2365
+ SyncReader.prototype.process = function () {
2261
2366
  // as long as there is any data and read requests
2262
2367
  while (this._reads.length > 0 && this._buffer.length) {
2368
+ let read = this._reads[0];
2263
2369
 
2264
- var read = this._reads[0];
2265
-
2266
- if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
2267
-
2370
+ if (
2371
+ this._buffer.length &&
2372
+ (this._buffer.length >= read.length || read.allowLess)
2373
+ ) {
2268
2374
  // ok there is any data so that we can satisfy this request
2269
2375
  this._reads.shift(); // == read
2270
2376
 
2271
- var buf = this._buffer;
2377
+ let buf = this._buffer;
2272
2378
 
2273
2379
  this._buffer = buf.slice(read.length);
2274
2380
 
2275
2381
  read.func.call(this, buf.slice(0, read.length));
2276
-
2277
- }
2278
- else {
2382
+ } else {
2279
2383
  break;
2280
2384
  }
2281
-
2282
2385
  }
2283
2386
 
2284
2387
  if (this._reads.length > 0) {
2285
- return new Error('There are some read requests waitng on finished stream');
2388
+ throw new Error("There are some read requests waitng on finished stream");
2286
2389
  }
2287
2390
 
2288
2391
  if (this._buffer.length > 0) {
2289
- return new Error('unrecognised content at end of stream');
2392
+ throw new Error("unrecognised content at end of stream");
2290
2393
  }
2291
-
2292
2394
  };
2293
2395
  });
2294
2396
 
2295
- var process_1 = function(inBuffer, bitmapInfo) {
2296
-
2297
- var outBuffers = [];
2298
- var reader = new syncReader(inBuffer);
2299
- var filter = new filterParse(bitmapInfo, {
2397
+ var process_1 = function (inBuffer, bitmapInfo) {
2398
+ let outBuffers = [];
2399
+ let reader = new syncReader(inBuffer);
2400
+ let filter = new filterParse(bitmapInfo, {
2300
2401
  read: reader.read.bind(reader),
2301
- write: function(bufferPart) {
2402
+ write: function (bufferPart) {
2302
2403
  outBuffers.push(bufferPart);
2303
2404
  },
2304
- complete: function() {
2305
- }
2405
+ complete: function () {},
2306
2406
  });
2307
2407
 
2308
2408
  filter.start();
@@ -2315,7 +2415,7 @@ var filterParseSync = {
2315
2415
  process: process_1
2316
2416
  };
2317
2417
 
2318
- var hasSyncZlib$1 = true;
2418
+ let hasSyncZlib$1 = true;
2319
2419
 
2320
2420
 
2321
2421
  if (!zlib__default['default'].deflateSync) {
@@ -2327,19 +2427,19 @@ if (!zlib__default['default'].deflateSync) {
2327
2427
 
2328
2428
 
2329
2429
 
2330
-
2331
- var parserSync = function(buffer, options) {
2332
-
2430
+ var parserSync = function (buffer, options) {
2333
2431
  if (!hasSyncZlib$1) {
2334
- throw new Error('To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0');
2432
+ throw new Error(
2433
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
2434
+ );
2335
2435
  }
2336
2436
 
2337
- var err;
2437
+ let err;
2338
2438
  function handleError(_err_) {
2339
2439
  err = _err_;
2340
2440
  }
2341
2441
 
2342
- var metaData;
2442
+ let metaData;
2343
2443
  function handleMetaData(_metaData_) {
2344
2444
  metaData = _metaData_;
2345
2445
  }
@@ -2356,19 +2456,19 @@ var parserSync = function(buffer, options) {
2356
2456
  metaData.alpha = true;
2357
2457
  }
2358
2458
 
2359
- var gamma;
2459
+ let gamma;
2360
2460
  function handleGamma(_gamma_) {
2361
2461
  gamma = _gamma_;
2362
2462
  }
2363
2463
 
2364
- var inflateDataList = [];
2464
+ let inflateDataList = [];
2365
2465
  function handleInflateData(inflatedData) {
2366
2466
  inflateDataList.push(inflatedData);
2367
2467
  }
2368
2468
 
2369
- var reader = new syncReader(buffer);
2469
+ let reader = new syncReader(buffer);
2370
2470
 
2371
- var parser$1 = new parser(options, {
2471
+ let parser$1 = new parser(options, {
2372
2472
  read: reader.read.bind(reader),
2373
2473
  error: handleError,
2374
2474
  metadata: handleMetaData,
@@ -2376,7 +2476,7 @@ var parserSync = function(buffer, options) {
2376
2476
  palette: handlePalette,
2377
2477
  transColor: handleTransColor,
2378
2478
  inflateData: handleInflateData,
2379
- simpleTransparency: handleSimpleTransparency
2479
+ simpleTransparency: handleSimpleTransparency,
2380
2480
  });
2381
2481
 
2382
2482
  parser$1.start();
@@ -2387,31 +2487,38 @@ var parserSync = function(buffer, options) {
2387
2487
  }
2388
2488
 
2389
2489
  //join together the inflate datas
2390
- var inflateData = Buffer.concat(inflateDataList);
2490
+ let inflateData = Buffer.concat(inflateDataList);
2391
2491
  inflateDataList.length = 0;
2392
2492
 
2393
- var inflatedData;
2493
+ let inflatedData;
2394
2494
  if (metaData.interlace) {
2395
2495
  inflatedData = zlib__default['default'].inflateSync(inflateData);
2396
- }
2397
- else {
2398
- var rowSize = ((metaData.width * metaData.bpp * metaData.depth + 7) >> 3) + 1;
2399
- var imageSize = rowSize * metaData.height;
2400
- inflatedData = syncInflate(inflateData, { chunkSize: imageSize, maxLength: imageSize });
2496
+ } else {
2497
+ let rowSize =
2498
+ ((metaData.width * metaData.bpp * metaData.depth + 7) >> 3) + 1;
2499
+ let imageSize = rowSize * metaData.height;
2500
+ inflatedData = syncInflate(inflateData, {
2501
+ chunkSize: imageSize,
2502
+ maxLength: imageSize,
2503
+ });
2401
2504
  }
2402
2505
  inflateData = null;
2403
2506
 
2404
2507
  if (!inflatedData || !inflatedData.length) {
2405
- throw new Error('bad png - invalid inflate data response');
2508
+ throw new Error("bad png - invalid inflate data response");
2406
2509
  }
2407
2510
 
2408
- var unfilteredData = filterParseSync.process(inflatedData, metaData);
2511
+ let unfilteredData = filterParseSync.process(inflatedData, metaData);
2409
2512
  inflateData = null;
2410
2513
 
2411
- var bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
2514
+ let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
2412
2515
  unfilteredData = null;
2413
2516
 
2414
- var normalisedBitmapData = formatNormaliser(bitmapData, metaData);
2517
+ let normalisedBitmapData = formatNormaliser(
2518
+ bitmapData,
2519
+ metaData,
2520
+ options.skipRescale
2521
+ );
2415
2522
 
2416
2523
  metaData.data = normalisedBitmapData;
2417
2524
  metaData.gamma = gamma || 0;
@@ -2419,7 +2526,7 @@ var parserSync = function(buffer, options) {
2419
2526
  return metaData;
2420
2527
  };
2421
2528
 
2422
- var hasSyncZlib = true;
2529
+ let hasSyncZlib = true;
2423
2530
 
2424
2531
  if (!zlib__default['default'].deflateSync) {
2425
2532
  hasSyncZlib = false;
@@ -2427,20 +2534,21 @@ if (!zlib__default['default'].deflateSync) {
2427
2534
 
2428
2535
 
2429
2536
 
2430
- var packerSync = function(metaData, opt) {
2431
-
2537
+ var packerSync = function (metaData, opt) {
2432
2538
  if (!hasSyncZlib) {
2433
- throw new Error('To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0');
2539
+ throw new Error(
2540
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
2541
+ );
2434
2542
  }
2435
2543
 
2436
- var options = opt || {};
2544
+ let options = opt || {};
2437
2545
 
2438
- var packer$1 = new packer(options);
2546
+ let packer$1 = new packer(options);
2439
2547
 
2440
- var chunks = [];
2548
+ let chunks = [];
2441
2549
 
2442
2550
  // Signature
2443
- chunks.push(new Buffer(constants.PNG_SIGNATURE));
2551
+ chunks.push(Buffer.from(constants.PNG_SIGNATURE));
2444
2552
 
2445
2553
  // Header
2446
2554
  chunks.push(packer$1.packIHDR(metaData.width, metaData.height));
@@ -2449,14 +2557,21 @@ var packerSync = function(metaData, opt) {
2449
2557
  chunks.push(packer$1.packGAMA(metaData.gamma));
2450
2558
  }
2451
2559
 
2452
- var filteredData = packer$1.filterData(metaData.data, metaData.width, metaData.height);
2560
+ let filteredData = packer$1.filterData(
2561
+ metaData.data,
2562
+ metaData.width,
2563
+ metaData.height
2564
+ );
2453
2565
 
2454
2566
  // compress it
2455
- var compressedData = zlib__default['default'].deflateSync(filteredData, packer$1.getDeflateOptions());
2567
+ let compressedData = zlib__default['default'].deflateSync(
2568
+ filteredData,
2569
+ packer$1.getDeflateOptions()
2570
+ );
2456
2571
  filteredData = null;
2457
2572
 
2458
2573
  if (!compressedData || !compressedData.length) {
2459
- throw new Error('bad png - invalid compressed data response');
2574
+ throw new Error("bad png - invalid compressed data response");
2460
2575
  }
2461
2576
  chunks.push(packer$1.packIDAT(compressedData));
2462
2577
 
@@ -2466,13 +2581,11 @@ var packerSync = function(metaData, opt) {
2466
2581
  return Buffer.concat(chunks);
2467
2582
  };
2468
2583
 
2469
- var read = function(buffer, options) {
2470
-
2584
+ var read = function (buffer, options) {
2471
2585
  return parserSync(buffer, options || {});
2472
2586
  };
2473
2587
 
2474
- var write = function(png, options) {
2475
-
2588
+ var write = function (png, options) {
2476
2589
  return packerSync(png, options);
2477
2590
  };
2478
2591
 
@@ -2489,8 +2602,7 @@ var png = createCommonjsModule(function (module, exports) {
2489
2602
 
2490
2603
 
2491
2604
 
2492
-
2493
- var PNG = exports.PNG = function(options) {
2605
+ let PNG = (exports.PNG = function (options) {
2494
2606
  Stream__default['default'].call(this);
2495
2607
 
2496
2608
  options = options || {}; // eslint-disable-line no-param-reassign
@@ -2499,8 +2611,10 @@ var PNG = exports.PNG = function(options) {
2499
2611
  this.width = options.width | 0;
2500
2612
  this.height = options.height | 0;
2501
2613
 
2502
- this.data = this.width > 0 && this.height > 0 ?
2503
- new Buffer(4 * this.width * this.height) : null;
2614
+ this.data =
2615
+ this.width > 0 && this.height > 0
2616
+ ? Buffer.alloc(4 * this.width * this.height)
2617
+ : null;
2504
2618
 
2505
2619
  if (options.fill && this.data) {
2506
2620
  this.data.fill(0);
@@ -2511,95 +2625,96 @@ var PNG = exports.PNG = function(options) {
2511
2625
 
2512
2626
  this._parser = new parserAsync(options);
2513
2627
 
2514
- this._parser.on('error', this.emit.bind(this, 'error'));
2515
- this._parser.on('close', this._handleClose.bind(this));
2516
- this._parser.on('metadata', this._metadata.bind(this));
2517
- this._parser.on('gamma', this._gamma.bind(this));
2518
- this._parser.on('parsed', function(data) {
2519
- this.data = data;
2520
- this.emit('parsed', data);
2521
- }.bind(this));
2628
+ this._parser.on("error", this.emit.bind(this, "error"));
2629
+ this._parser.on("close", this._handleClose.bind(this));
2630
+ this._parser.on("metadata", this._metadata.bind(this));
2631
+ this._parser.on("gamma", this._gamma.bind(this));
2632
+ this._parser.on(
2633
+ "parsed",
2634
+ function (data) {
2635
+ this.data = data;
2636
+ this.emit("parsed", data);
2637
+ }.bind(this)
2638
+ );
2522
2639
 
2523
2640
  this._packer = new packerAsync(options);
2524
- this._packer.on('data', this.emit.bind(this, 'data'));
2525
- this._packer.on('end', this.emit.bind(this, 'end'));
2526
- this._parser.on('close', this._handleClose.bind(this));
2527
- this._packer.on('error', this.emit.bind(this, 'error'));
2528
-
2529
- };
2641
+ this._packer.on("data", this.emit.bind(this, "data"));
2642
+ this._packer.on("end", this.emit.bind(this, "end"));
2643
+ this._parser.on("close", this._handleClose.bind(this));
2644
+ this._packer.on("error", this.emit.bind(this, "error"));
2645
+ });
2530
2646
  util__default['default'].inherits(PNG, Stream__default['default']);
2531
2647
 
2532
2648
  PNG.sync = pngSync;
2533
2649
 
2534
- PNG.prototype.pack = function() {
2535
-
2650
+ PNG.prototype.pack = function () {
2536
2651
  if (!this.data || !this.data.length) {
2537
- this.emit('error', 'No data provided');
2652
+ this.emit("error", "No data provided");
2538
2653
  return this;
2539
2654
  }
2540
2655
 
2541
- process.nextTick(function() {
2542
- this._packer.pack(this.data, this.width, this.height, this.gamma);
2543
- }.bind(this));
2656
+ process.nextTick(
2657
+ function () {
2658
+ this._packer.pack(this.data, this.width, this.height, this.gamma);
2659
+ }.bind(this)
2660
+ );
2544
2661
 
2545
2662
  return this;
2546
2663
  };
2547
2664
 
2548
-
2549
- PNG.prototype.parse = function(data, callback) {
2550
-
2665
+ PNG.prototype.parse = function (data, callback) {
2551
2666
  if (callback) {
2552
- var onParsed, onError;
2667
+ let onParsed, onError;
2553
2668
 
2554
- onParsed = function(parsedData) {
2555
- this.removeListener('error', onError);
2669
+ onParsed = function (parsedData) {
2670
+ this.removeListener("error", onError);
2556
2671
 
2557
2672
  this.data = parsedData;
2558
2673
  callback(null, this);
2559
2674
  }.bind(this);
2560
2675
 
2561
- onError = function(err) {
2562
- this.removeListener('parsed', onParsed);
2676
+ onError = function (err) {
2677
+ this.removeListener("parsed", onParsed);
2563
2678
 
2564
2679
  callback(err, null);
2565
2680
  }.bind(this);
2566
2681
 
2567
- this.once('parsed', onParsed);
2568
- this.once('error', onError);
2682
+ this.once("parsed", onParsed);
2683
+ this.once("error", onError);
2569
2684
  }
2570
2685
 
2571
2686
  this.end(data);
2572
2687
  return this;
2573
2688
  };
2574
2689
 
2575
- PNG.prototype.write = function(data) {
2690
+ PNG.prototype.write = function (data) {
2576
2691
  this._parser.write(data);
2577
2692
  return true;
2578
2693
  };
2579
2694
 
2580
- PNG.prototype.end = function(data) {
2695
+ PNG.prototype.end = function (data) {
2581
2696
  this._parser.end(data);
2582
2697
  };
2583
2698
 
2584
- PNG.prototype._metadata = function(metadata) {
2699
+ PNG.prototype._metadata = function (metadata) {
2585
2700
  this.width = metadata.width;
2586
2701
  this.height = metadata.height;
2587
2702
 
2588
- this.emit('metadata', metadata);
2703
+ this.emit("metadata", metadata);
2589
2704
  };
2590
2705
 
2591
- PNG.prototype._gamma = function(gamma) {
2706
+ PNG.prototype._gamma = function (gamma) {
2592
2707
  this.gamma = gamma;
2593
2708
  };
2594
2709
 
2595
- PNG.prototype._handleClose = function() {
2710
+ PNG.prototype._handleClose = function () {
2596
2711
  if (!this._parser.writable && !this._packer.readable) {
2597
- this.emit('close');
2712
+ this.emit("close");
2598
2713
  }
2599
2714
  };
2600
2715
 
2601
-
2602
- PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
2716
+ PNG.bitblt = function (src, dst, srcX, srcY, width, height, deltaX, deltaY) {
2717
+ // eslint-disable-line max-params
2603
2718
  // coerce pixel dimensions to integers (also coerces undefined -> 0):
2604
2719
  /* eslint-disable no-param-reassign */
2605
2720
  srcX |= 0;
@@ -2610,16 +2725,27 @@ PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) { //
2610
2725
  deltaY |= 0;
2611
2726
  /* eslint-enable no-param-reassign */
2612
2727
 
2613
- if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
2614
- throw new Error('bitblt reading outside image');
2728
+ if (
2729
+ srcX > src.width ||
2730
+ srcY > src.height ||
2731
+ srcX + width > src.width ||
2732
+ srcY + height > src.height
2733
+ ) {
2734
+ throw new Error("bitblt reading outside image");
2615
2735
  }
2616
2736
 
2617
- if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
2618
- throw new Error('bitblt writing outside image');
2737
+ if (
2738
+ deltaX > dst.width ||
2739
+ deltaY > dst.height ||
2740
+ deltaX + width > dst.width ||
2741
+ deltaY + height > dst.height
2742
+ ) {
2743
+ throw new Error("bitblt writing outside image");
2619
2744
  }
2620
2745
 
2621
- for (var y = 0; y < height; y++) {
2622
- src.data.copy(dst.data,
2746
+ for (let y = 0; y < height; y++) {
2747
+ src.data.copy(
2748
+ dst.data,
2623
2749
  ((deltaY + y) * dst.width + deltaX) << 2,
2624
2750
  ((srcY + y) * src.width + srcX) << 2,
2625
2751
  ((srcY + y) * src.width + srcX + width) << 2
@@ -2627,21 +2753,29 @@ PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) { //
2627
2753
  }
2628
2754
  };
2629
2755
 
2630
-
2631
- PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
2756
+ PNG.prototype.bitblt = function (
2757
+ dst,
2758
+ srcX,
2759
+ srcY,
2760
+ width,
2761
+ height,
2762
+ deltaX,
2763
+ deltaY
2764
+ ) {
2765
+ // eslint-disable-line max-params
2632
2766
 
2633
2767
  PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
2634
2768
  return this;
2635
2769
  };
2636
2770
 
2637
- PNG.adjustGamma = function(src) {
2771
+ PNG.adjustGamma = function (src) {
2638
2772
  if (src.gamma) {
2639
- for (var y = 0; y < src.height; y++) {
2640
- for (var x = 0; x < src.width; x++) {
2641
- var idx = (src.width * y + x) << 2;
2773
+ for (let y = 0; y < src.height; y++) {
2774
+ for (let x = 0; x < src.width; x++) {
2775
+ let idx = (src.width * y + x) << 2;
2642
2776
 
2643
- for (var i = 0; i < 3; i++) {
2644
- var sample = src.data[idx + i] / 255;
2777
+ for (let i = 0; i < 3; i++) {
2778
+ let sample = src.data[idx + i] / 255;
2645
2779
  sample = Math.pow(sample, 1 / 2.2 / src.gamma);
2646
2780
  src.data[idx + i] = Math.round(sample * 255);
2647
2781
  }
@@ -2651,7 +2785,7 @@ PNG.adjustGamma = function(src) {
2651
2785
  }
2652
2786
  };
2653
2787
 
2654
- PNG.prototype.adjustGamma = function() {
2788
+ PNG.prototype.adjustGamma = function () {
2655
2789
  PNG.adjustGamma(this);
2656
2790
  };
2657
2791
  });