nftychat-universe 0.1.8 → 0.1.10

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 (3) hide show
  1. package/dist/index.cjs.js +2210 -1918
  2. package/dist/index.esm.js +2204 -1918
  3. package/package.json +2 -1
package/dist/index.cjs.js CHANGED
@@ -5,6 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React48 = require('react');
6
6
  var wagmi = require('wagmi');
7
7
  var reactDom = require('react-dom');
8
+ var require$$1$2 = require('fs');
9
+ var require$$0 = require('util');
10
+ var require$$1 = require('stream');
11
+ var require$$1$1 = require('zlib');
12
+ var require$$0$1 = require('assert');
13
+ var require$$3 = require('buffer');
8
14
  var walletConnect$1 = require('wagmi/connectors/walletConnect');
9
15
  var injected$1 = require('wagmi/connectors/injected');
10
16
  var coinbaseWallet = require('wagmi/connectors/coinbaseWallet');
@@ -38,6 +44,12 @@ function _interopNamespace(e) {
38
44
 
39
45
  var React48__namespace = /*#__PURE__*/_interopNamespace(React48);
40
46
  var React48__default = /*#__PURE__*/_interopDefaultLegacy(React48);
47
+ var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
48
+ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
49
+ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
50
+ var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
51
+ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
52
+ var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
41
53
  var toast__default = /*#__PURE__*/_interopDefaultLegacy(toast);
42
54
  var Popover__default = /*#__PURE__*/_interopDefaultLegacy(Popover);
43
55
 
@@ -265,232 +277,6 @@ function createMapValueFn(properties) {
265
277
  });
266
278
  }
267
279
 
268
- var global$1 = (typeof global !== "undefined" ? global :
269
- typeof self !== "undefined" ? self :
270
- typeof window !== "undefined" ? window : {});
271
-
272
- // shim for using process in browser
273
- // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
274
-
275
- function defaultSetTimout() {
276
- throw new Error('setTimeout has not been defined');
277
- }
278
- function defaultClearTimeout () {
279
- throw new Error('clearTimeout has not been defined');
280
- }
281
- var cachedSetTimeout = defaultSetTimout;
282
- var cachedClearTimeout = defaultClearTimeout;
283
- if (typeof global$1.setTimeout === 'function') {
284
- cachedSetTimeout = setTimeout;
285
- }
286
- if (typeof global$1.clearTimeout === 'function') {
287
- cachedClearTimeout = clearTimeout;
288
- }
289
-
290
- function runTimeout(fun) {
291
- if (cachedSetTimeout === setTimeout) {
292
- //normal enviroments in sane situations
293
- return setTimeout(fun, 0);
294
- }
295
- // if setTimeout wasn't available but was latter defined
296
- if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
297
- cachedSetTimeout = setTimeout;
298
- return setTimeout(fun, 0);
299
- }
300
- try {
301
- // when when somebody has screwed with setTimeout but no I.E. maddness
302
- return cachedSetTimeout(fun, 0);
303
- } catch(e){
304
- try {
305
- // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
306
- return cachedSetTimeout.call(null, fun, 0);
307
- } catch(e){
308
- // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
309
- return cachedSetTimeout.call(this, fun, 0);
310
- }
311
- }
312
-
313
-
314
- }
315
- function runClearTimeout(marker) {
316
- if (cachedClearTimeout === clearTimeout) {
317
- //normal enviroments in sane situations
318
- return clearTimeout(marker);
319
- }
320
- // if clearTimeout wasn't available but was latter defined
321
- if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
322
- cachedClearTimeout = clearTimeout;
323
- return clearTimeout(marker);
324
- }
325
- try {
326
- // when when somebody has screwed with setTimeout but no I.E. maddness
327
- return cachedClearTimeout(marker);
328
- } catch (e){
329
- try {
330
- // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
331
- return cachedClearTimeout.call(null, marker);
332
- } catch (e){
333
- // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
334
- // Some versions of I.E. have different rules for clearTimeout vs setTimeout
335
- return cachedClearTimeout.call(this, marker);
336
- }
337
- }
338
-
339
-
340
-
341
- }
342
- var queue = [];
343
- var draining = false;
344
- var currentQueue;
345
- var queueIndex = -1;
346
-
347
- function cleanUpNextTick() {
348
- if (!draining || !currentQueue) {
349
- return;
350
- }
351
- draining = false;
352
- if (currentQueue.length) {
353
- queue = currentQueue.concat(queue);
354
- } else {
355
- queueIndex = -1;
356
- }
357
- if (queue.length) {
358
- drainQueue();
359
- }
360
- }
361
-
362
- function drainQueue() {
363
- if (draining) {
364
- return;
365
- }
366
- var timeout = runTimeout(cleanUpNextTick);
367
- draining = true;
368
-
369
- var len = queue.length;
370
- while(len) {
371
- currentQueue = queue;
372
- queue = [];
373
- while (++queueIndex < len) {
374
- if (currentQueue) {
375
- currentQueue[queueIndex].run();
376
- }
377
- }
378
- queueIndex = -1;
379
- len = queue.length;
380
- }
381
- currentQueue = null;
382
- draining = false;
383
- runClearTimeout(timeout);
384
- }
385
- function nextTick(fun) {
386
- var args = new Array(arguments.length - 1);
387
- if (arguments.length > 1) {
388
- for (var i = 1; i < arguments.length; i++) {
389
- args[i - 1] = arguments[i];
390
- }
391
- }
392
- queue.push(new Item(fun, args));
393
- if (queue.length === 1 && !draining) {
394
- runTimeout(drainQueue);
395
- }
396
- }
397
- // v8 likes predictible objects
398
- function Item(fun, array) {
399
- this.fun = fun;
400
- this.array = array;
401
- }
402
- Item.prototype.run = function () {
403
- this.fun.apply(null, this.array);
404
- };
405
- var title = 'browser';
406
- var platform = 'browser';
407
- var browser$1 = true;
408
- var env = {};
409
- var argv = [];
410
- var version$1 = ''; // empty string to avoid regexp issues
411
- var versions = {};
412
- var release = {};
413
- var config = {};
414
-
415
- function noop$1() {}
416
-
417
- var on = noop$1;
418
- var addListener = noop$1;
419
- var once = noop$1;
420
- var off = noop$1;
421
- var removeListener = noop$1;
422
- var removeAllListeners = noop$1;
423
- var emit = noop$1;
424
-
425
- function binding(name) {
426
- throw new Error('process.binding is not supported');
427
- }
428
-
429
- function cwd () { return '/' }
430
- function chdir (dir) {
431
- throw new Error('process.chdir is not supported');
432
- }function umask() { return 0; }
433
-
434
- // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
435
- var performance = global$1.performance || {};
436
- var performanceNow =
437
- performance.now ||
438
- performance.mozNow ||
439
- performance.msNow ||
440
- performance.oNow ||
441
- performance.webkitNow ||
442
- function(){ return (new Date()).getTime() };
443
-
444
- // generate timestamp or delta
445
- // see http://nodejs.org/api/process.html#process_process_hrtime
446
- function hrtime(previousTimestamp){
447
- var clocktime = performanceNow.call(performance)*1e-3;
448
- var seconds = Math.floor(clocktime);
449
- var nanoseconds = Math.floor((clocktime%1)*1e9);
450
- if (previousTimestamp) {
451
- seconds = seconds - previousTimestamp[0];
452
- nanoseconds = nanoseconds - previousTimestamp[1];
453
- if (nanoseconds<0) {
454
- seconds--;
455
- nanoseconds += 1e9;
456
- }
457
- }
458
- return [seconds,nanoseconds]
459
- }
460
-
461
- var startTime = new Date();
462
- function uptime() {
463
- var currentTime = new Date();
464
- var dif = currentTime - startTime;
465
- return dif / 1000;
466
- }
467
-
468
- var browser$1$1 = {
469
- nextTick: nextTick,
470
- title: title,
471
- browser: browser$1,
472
- env: env,
473
- argv: argv,
474
- version: version$1,
475
- versions: versions,
476
- on: on,
477
- addListener: addListener,
478
- once: once,
479
- off: off,
480
- removeListener: removeListener,
481
- removeAllListeners: removeAllListeners,
482
- emit: emit,
483
- binding: binding,
484
- cwd: cwd,
485
- chdir: chdir,
486
- umask: umask,
487
- hrtime: hrtime,
488
- platform: platform,
489
- release: release,
490
- config: config,
491
- uptime: uptime
492
- };
493
-
494
280
  function _defineProperty(obj, key, value) {
495
281
  if (key in obj) {
496
282
  Object.defineProperty(obj, key, {
@@ -591,7 +377,7 @@ var createSprinkles$1 = composeStyles => function () {
591
377
  }
592
378
 
593
379
  if (typeof propValue === 'string' || typeof propValue === 'number') {
594
- if (browser$1$1.env.NODE_ENV !== 'production') {
380
+ if (process.env.NODE_ENV !== 'production') {
595
381
  if (!_sprinkle.values[propValue].defaultClass) {
596
382
  throw new Error();
597
383
  }
@@ -605,7 +391,7 @@ var createSprinkles$1 = composeStyles => function () {
605
391
  if (responsiveValue != null) {
606
392
  var conditionName = _sprinkle.responsiveArray[responsiveIndex];
607
393
 
608
- if (browser$1$1.env.NODE_ENV !== 'production') {
394
+ if (process.env.NODE_ENV !== 'production') {
609
395
  if (!_sprinkle.values[responsiveValue].conditions[conditionName]) {
610
396
  throw new Error();
611
397
  }
@@ -620,7 +406,7 @@ var createSprinkles$1 = composeStyles => function () {
620
406
  var _value = propValue[_conditionName];
621
407
 
622
408
  if (_value != null) {
623
- if (browser$1$1.env.NODE_ENV !== 'production') {
409
+ if (process.env.NODE_ENV !== 'production') {
624
410
  if (!_sprinkle.values[_value].conditions[_conditionName]) {
625
411
  throw new Error();
626
412
  }
@@ -631,7 +417,7 @@ var createSprinkles$1 = composeStyles => function () {
631
417
  }
632
418
  }
633
419
  } catch (e) {
634
- if (browser$1$1.env.NODE_ENV !== 'production') {
420
+ if (process.env.NODE_ENV !== 'production') {
635
421
  (function () {
636
422
  class SprinklesError extends Error {
637
423
  constructor(message) {
@@ -1119,10 +905,10 @@ var zeroGap = {
1119
905
  right: 0,
1120
906
  gap: 0,
1121
907
  };
1122
- var parse = function (x) { return parseInt(x || '', 10) || 0; };
908
+ var parse$1 = function (x) { return parseInt(x || '', 10) || 0; };
1123
909
  var getOffset = function (gapMode) {
1124
910
  var cs = window.getComputedStyle(document.body);
1125
- if (browser$1$1.env.NODE_ENV !== 'production') {
911
+ if (process.env.NODE_ENV !== 'production') {
1126
912
  if (cs.overflowY === 'hidden') {
1127
913
  console.error('react-remove-scroll-bar: cannot calculate scrollbar size because it is removed (overflow:hidden on body');
1128
914
  }
@@ -1130,7 +916,7 @@ var getOffset = function (gapMode) {
1130
916
  var left = cs[gapMode === 'padding' ? 'paddingLeft' : 'marginLeft'];
1131
917
  var top = cs[gapMode === 'padding' ? 'paddingTop' : 'marginTop'];
1132
918
  var right = cs[gapMode === 'padding' ? 'paddingRight' : 'marginRight'];
1133
- return [parse(left), parse(top), parse(right)];
919
+ return [parse$1(left), parse$1(top), parse$1(right)];
1134
920
  };
1135
921
  var getGapWidth = function (gapMode) {
1136
922
  if (gapMode === void 0) { gapMode = 'margin'; }
@@ -1505,27 +1291,6 @@ function getDefaultExportFromCjs (x) {
1505
1291
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1506
1292
  }
1507
1293
 
1508
- function getAugmentedNamespace(n) {
1509
- var f = n.default;
1510
- if (typeof f == "function") {
1511
- var a = function () {
1512
- return f.apply(this, arguments);
1513
- };
1514
- a.prototype = f.prototype;
1515
- } else a = {};
1516
- Object.defineProperty(a, '__esModule', {value: true});
1517
- Object.keys(n).forEach(function (k) {
1518
- var d = Object.getOwnPropertyDescriptor(n, k);
1519
- Object.defineProperty(a, k, d.get ? d : {
1520
- enumerable: true,
1521
- get: function () {
1522
- return n[k];
1523
- }
1524
- });
1525
- });
1526
- return a;
1527
- }
1528
-
1529
1294
  var lib = {exports: {}};
1530
1295
 
1531
1296
  var server = {};
@@ -2842,11 +2607,11 @@ regex.testAlphanumeric = function testAlphanumeric (str) {
2842
2607
 
2843
2608
  var formatInfo = {};
2844
2609
 
2845
- const Utils$4 = utils$1;
2610
+ const Utils$3 = utils$1;
2846
2611
 
2847
2612
  const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
2848
2613
  const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
2849
- const G15_BCH = Utils$4.getBCHDigit(G15);
2614
+ const G15_BCH = Utils$3.getBCHDigit(G15);
2850
2615
 
2851
2616
  /**
2852
2617
  * Returns format information with relative error correction bits
@@ -2862,8 +2627,8 @@ formatInfo.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask)
2862
2627
  const data = ((errorCorrectionLevel.bit << 3) | mask);
2863
2628
  let d = data << 10;
2864
2629
 
2865
- while (Utils$4.getBCHDigit(d) - G15_BCH >= 0) {
2866
- d ^= (G15 << (Utils$4.getBCHDigit(d) - G15_BCH));
2630
+ while (Utils$3.getBCHDigit(d) - G15_BCH >= 0) {
2631
+ d ^= (G15 << (Utils$3.getBCHDigit(d) - G15_BCH));
2867
2632
  }
2868
2633
 
2869
2634
  // xor final data with mask pattern in order to ensure that
@@ -3061,7 +2826,7 @@ ByteData.prototype.write = function (bitBuffer) {
3061
2826
  var byteData = ByteData;
3062
2827
 
3063
2828
  const Mode$1 = mode;
3064
- const Utils$3 = utils$1;
2829
+ const Utils$2 = utils$1;
3065
2830
 
3066
2831
  function KanjiData (data) {
3067
2832
  this.mode = Mode$1.KANJI;
@@ -3087,7 +2852,7 @@ KanjiData.prototype.write = function (bitBuffer) {
3087
2852
  // These byte values are shifted from the JIS X 0208 values.
3088
2853
  // JIS X 0208 gives details of the shift coded representation.
3089
2854
  for (i = 0; i < this.data.length; i++) {
3090
- let value = Utils$3.toSJIS(this.data[i]);
2855
+ let value = Utils$2.toSJIS(this.data[i]);
3091
2856
 
3092
2857
  // For characters with Shift JIS values from 0x8140 to 0x9FFC:
3093
2858
  if (value >= 0x8140 && value <= 0x9FFC) {
@@ -3616,7 +3381,7 @@ var dijkstra = {exports: {}};
3616
3381
  };
3617
3382
  } (segments));
3618
3383
 
3619
- const Utils$2 = utils$1;
3384
+ const Utils$1 = utils$1;
3620
3385
  const ECLevel = errorCorrectionLevel;
3621
3386
  const BitBuffer = bitBuffer;
3622
3387
  const BitMatrix = bitMatrix;
@@ -3868,7 +3633,7 @@ function createData (version, errorCorrectionLevel, segments) {
3868
3633
  });
3869
3634
 
3870
3635
  // Calculate required number of bits
3871
- const totalCodewords = Utils$2.getSymbolTotalCodewords(version);
3636
+ const totalCodewords = Utils$1.getSymbolTotalCodewords(version);
3872
3637
  const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
3873
3638
  const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
3874
3639
 
@@ -3913,7 +3678,7 @@ function createData (version, errorCorrectionLevel, segments) {
3913
3678
  */
3914
3679
  function createCodewords (bitBuffer, version, errorCorrectionLevel) {
3915
3680
  // Total codewords for this QR code version (Data + Error correction)
3916
- const totalCodewords = Utils$2.getSymbolTotalCodewords(version);
3681
+ const totalCodewords = Utils$1.getSymbolTotalCodewords(version);
3917
3682
 
3918
3683
  // Total number of error correction codewords
3919
3684
  const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
@@ -4038,7 +3803,7 @@ function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
4038
3803
  const dataBits = createData(version, errorCorrectionLevel, segments);
4039
3804
 
4040
3805
  // Allocate matrix buffer
4041
- const moduleCount = Utils$2.getSymbolSize(version);
3806
+ const moduleCount = Utils$1.getSymbolSize(version);
4042
3807
  const modules = new BitMatrix(moduleCount);
4043
3808
 
4044
3809
  // Add function modules
@@ -4105,2072 +3870,2525 @@ qrcode.create = function create (data, options) {
4105
3870
  mask = MaskPattern.from(options.maskPattern);
4106
3871
 
4107
3872
  if (options.toSJISFunc) {
4108
- Utils$2.setToSJISFunction(options.toSJISFunc);
3873
+ Utils$1.setToSJISFunction(options.toSJISFunc);
4109
3874
  }
4110
3875
  }
4111
3876
 
4112
3877
  return createSymbol(data, version, errorCorrectionLevel, mask)
4113
3878
  };
4114
3879
 
4115
- var lookup = [];
4116
- var revLookup = [];
4117
- var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
4118
- var inited = false;
4119
- function init () {
4120
- inited = true;
4121
- var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
4122
- for (var i = 0, len = code.length; i < len; ++i) {
4123
- lookup[i] = code[i];
4124
- revLookup[code.charCodeAt(i)] = i;
4125
- }
3880
+ var png$1 = {};
4126
3881
 
4127
- revLookup['-'.charCodeAt(0)] = 62;
4128
- revLookup['_'.charCodeAt(0)] = 63;
4129
- }
3882
+ var png = {};
4130
3883
 
4131
- function toByteArray (b64) {
4132
- if (!inited) {
4133
- init();
4134
- }
4135
- var i, j, l, tmp, placeHolders, arr;
4136
- var len = b64.length;
3884
+ var parserAsync = {exports: {}};
4137
3885
 
4138
- if (len % 4 > 0) {
4139
- throw new Error('Invalid string. Length must be a multiple of 4')
4140
- }
3886
+ var chunkstream = {exports: {}};
4141
3887
 
4142
- // the number of equal signs (place holders)
4143
- // if there are two placeholders, than the two characters before it
4144
- // represent one byte
4145
- // if there is only one, then the three characters before it represent 2 bytes
4146
- // this is just a cheap hack to not do indexOf twice
4147
- placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
3888
+ let util$4 = require$$0__default["default"];
3889
+ let Stream$2 = require$$1__default["default"];
4148
3890
 
4149
- // base64 is 4/3 + up to two characters of the original data
4150
- arr = new Arr(len * 3 / 4 - placeHolders);
3891
+ let ChunkStream$2 = (chunkstream.exports = function () {
3892
+ Stream$2.call(this);
4151
3893
 
4152
- // if there are placeholders, only get up to the last complete 4 chars
4153
- l = placeHolders > 0 ? len - 4 : len;
3894
+ this._buffers = [];
3895
+ this._buffered = 0;
4154
3896
 
4155
- var L = 0;
3897
+ this._reads = [];
3898
+ this._paused = false;
4156
3899
 
4157
- for (i = 0, j = 0; i < l; i += 4, j += 3) {
4158
- tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
4159
- arr[L++] = (tmp >> 16) & 0xFF;
4160
- arr[L++] = (tmp >> 8) & 0xFF;
4161
- arr[L++] = tmp & 0xFF;
4162
- }
3900
+ this._encoding = "utf8";
3901
+ this.writable = true;
3902
+ });
3903
+ util$4.inherits(ChunkStream$2, Stream$2);
4163
3904
 
4164
- if (placeHolders === 2) {
4165
- tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
4166
- arr[L++] = tmp & 0xFF;
4167
- } else if (placeHolders === 1) {
4168
- tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
4169
- arr[L++] = (tmp >> 8) & 0xFF;
4170
- arr[L++] = tmp & 0xFF;
4171
- }
3905
+ ChunkStream$2.prototype.read = function (length, callback) {
3906
+ this._reads.push({
3907
+ length: Math.abs(length), // if length < 0 then at most this length
3908
+ allowLess: length < 0,
3909
+ func: callback,
3910
+ });
4172
3911
 
4173
- return arr
4174
- }
3912
+ process.nextTick(
3913
+ function () {
3914
+ this._process();
4175
3915
 
4176
- function tripletToBase64 (num) {
4177
- return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
4178
- }
3916
+ // its paused and there is not enought data then ask for more
3917
+ if (this._paused && this._reads && this._reads.length > 0) {
3918
+ this._paused = false;
4179
3919
 
4180
- function encodeChunk (uint8, start, end) {
4181
- var tmp;
4182
- var output = [];
4183
- for (var i = start; i < end; i += 3) {
4184
- tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
4185
- output.push(tripletToBase64(tmp));
4186
- }
4187
- return output.join('')
4188
- }
3920
+ this.emit("drain");
3921
+ }
3922
+ }.bind(this)
3923
+ );
3924
+ };
4189
3925
 
4190
- function fromByteArray (uint8) {
4191
- if (!inited) {
4192
- init();
3926
+ ChunkStream$2.prototype.write = function (data, encoding) {
3927
+ if (!this.writable) {
3928
+ this.emit("error", new Error("Stream not writable"));
3929
+ return false;
4193
3930
  }
4194
- var tmp;
4195
- var len = uint8.length;
4196
- var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
4197
- var output = '';
4198
- var parts = [];
4199
- var maxChunkLength = 16383; // must be multiple of 3
4200
3931
 
4201
- // go through the array every three bytes, we'll deal with trailing stuff later
4202
- for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
4203
- parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
3932
+ let dataBuffer;
3933
+ if (Buffer.isBuffer(data)) {
3934
+ dataBuffer = data;
3935
+ } else {
3936
+ dataBuffer = Buffer.from(data, encoding || this._encoding);
4204
3937
  }
4205
3938
 
4206
- // pad the end with zeros, but make sure to not forget the extra bytes
4207
- if (extraBytes === 1) {
4208
- tmp = uint8[len - 1];
4209
- output += lookup[tmp >> 2];
4210
- output += lookup[(tmp << 4) & 0x3F];
4211
- output += '==';
4212
- } else if (extraBytes === 2) {
4213
- tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
4214
- output += lookup[tmp >> 10];
4215
- output += lookup[(tmp >> 4) & 0x3F];
4216
- output += lookup[(tmp << 2) & 0x3F];
4217
- output += '=';
4218
- }
3939
+ this._buffers.push(dataBuffer);
3940
+ this._buffered += dataBuffer.length;
4219
3941
 
4220
- parts.push(output);
3942
+ this._process();
4221
3943
 
4222
- return parts.join('')
4223
- }
3944
+ // ok if there are no more read requests
3945
+ if (this._reads && this._reads.length === 0) {
3946
+ this._paused = true;
3947
+ }
4224
3948
 
4225
- function read (buffer, offset, isLE, mLen, nBytes) {
4226
- var e, m;
4227
- var eLen = nBytes * 8 - mLen - 1;
4228
- var eMax = (1 << eLen) - 1;
4229
- var eBias = eMax >> 1;
4230
- var nBits = -7;
4231
- var i = isLE ? (nBytes - 1) : 0;
4232
- var d = isLE ? -1 : 1;
4233
- var s = buffer[offset + i];
3949
+ return this.writable && !this._paused;
3950
+ };
4234
3951
 
4235
- i += d;
3952
+ ChunkStream$2.prototype.end = function (data, encoding) {
3953
+ if (data) {
3954
+ this.write(data, encoding);
3955
+ }
4236
3956
 
4237
- e = s & ((1 << (-nBits)) - 1);
4238
- s >>= (-nBits);
4239
- nBits += eLen;
4240
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
3957
+ this.writable = false;
4241
3958
 
4242
- m = e & ((1 << (-nBits)) - 1);
4243
- e >>= (-nBits);
4244
- nBits += mLen;
4245
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
3959
+ // already destroyed
3960
+ if (!this._buffers) {
3961
+ return;
3962
+ }
4246
3963
 
4247
- if (e === 0) {
4248
- e = 1 - eBias;
4249
- } else if (e === eMax) {
4250
- return m ? NaN : ((s ? -1 : 1) * Infinity)
3964
+ // enqueue or handle end
3965
+ if (this._buffers.length === 0) {
3966
+ this._end();
4251
3967
  } else {
4252
- m = m + Math.pow(2, mLen);
4253
- e = e - eBias;
3968
+ this._buffers.push(null);
3969
+ this._process();
4254
3970
  }
4255
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
4256
- }
4257
-
4258
- function write (buffer, value, offset, isLE, mLen, nBytes) {
4259
- var e, m, c;
4260
- var eLen = nBytes * 8 - mLen - 1;
4261
- var eMax = (1 << eLen) - 1;
4262
- var eBias = eMax >> 1;
4263
- var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
4264
- var i = isLE ? 0 : (nBytes - 1);
4265
- var d = isLE ? 1 : -1;
4266
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
4267
-
4268
- value = Math.abs(value);
3971
+ };
4269
3972
 
4270
- if (isNaN(value) || value === Infinity) {
4271
- m = isNaN(value) ? 1 : 0;
4272
- e = eMax;
4273
- } else {
4274
- e = Math.floor(Math.log(value) / Math.LN2);
4275
- if (value * (c = Math.pow(2, -e)) < 1) {
4276
- e--;
4277
- c *= 2;
4278
- }
4279
- if (e + eBias >= 1) {
4280
- value += rt / c;
4281
- } else {
4282
- value += rt * Math.pow(2, 1 - eBias);
4283
- }
4284
- if (value * c >= 2) {
4285
- e++;
4286
- c /= 2;
4287
- }
3973
+ ChunkStream$2.prototype.destroySoon = ChunkStream$2.prototype.end;
4288
3974
 
4289
- if (e + eBias >= eMax) {
4290
- m = 0;
4291
- e = eMax;
4292
- } else if (e + eBias >= 1) {
4293
- m = (value * c - 1) * Math.pow(2, mLen);
4294
- e = e + eBias;
4295
- } else {
4296
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
4297
- e = 0;
4298
- }
3975
+ ChunkStream$2.prototype._end = function () {
3976
+ if (this._reads.length > 0) {
3977
+ this.emit("error", new Error("Unexpected end of input"));
4299
3978
  }
4300
3979
 
4301
- for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
4302
-
4303
- e = (e << mLen) | m;
4304
- eLen += mLen;
4305
- for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
3980
+ this.destroy();
3981
+ };
4306
3982
 
4307
- buffer[offset + i - d] |= s * 128;
4308
- }
3983
+ ChunkStream$2.prototype.destroy = function () {
3984
+ if (!this._buffers) {
3985
+ return;
3986
+ }
4309
3987
 
4310
- var toString = {}.toString;
3988
+ this.writable = false;
3989
+ this._reads = null;
3990
+ this._buffers = null;
4311
3991
 
4312
- var isArray = Array.isArray || function (arr) {
4313
- return toString.call(arr) == '[object Array]';
3992
+ this.emit("close");
4314
3993
  };
4315
3994
 
4316
- /*!
4317
- * The buffer module from node.js, for the browser.
4318
- *
4319
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
4320
- * @license MIT
4321
- */
3995
+ ChunkStream$2.prototype._processReadAllowingLess = function (read) {
3996
+ // ok there is any data so that we can satisfy this request
3997
+ this._reads.shift(); // == read
4322
3998
 
4323
- var INSPECT_MAX_BYTES = 50;
3999
+ // first we need to peek into first buffer
4000
+ let smallerBuf = this._buffers[0];
4324
4001
 
4325
- /**
4326
- * If `Buffer.TYPED_ARRAY_SUPPORT`:
4327
- * === true Use Uint8Array implementation (fastest)
4328
- * === false Use Object implementation (most compatible, even IE6)
4329
- *
4330
- * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
4331
- * Opera 11.6+, iOS 4.2+.
4332
- *
4333
- * Due to various browser bugs, sometimes the Object implementation will be used even
4334
- * when the browser supports typed arrays.
4335
- *
4336
- * Note:
4337
- *
4338
- * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
4339
- * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
4340
- *
4341
- * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
4342
- *
4343
- * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
4344
- * incorrect length in some situations.
4002
+ // ok there is more data than we need
4003
+ if (smallerBuf.length > read.length) {
4004
+ this._buffered -= read.length;
4005
+ this._buffers[0] = smallerBuf.slice(read.length);
4345
4006
 
4346
- * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
4347
- * get the Object implementation, which is slower but behaves correctly.
4348
- */
4349
- Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
4350
- ? global$1.TYPED_ARRAY_SUPPORT
4351
- : true;
4007
+ read.func.call(this, smallerBuf.slice(0, read.length));
4008
+ } else {
4009
+ // ok this is less than maximum length so use it all
4010
+ this._buffered -= smallerBuf.length;
4011
+ this._buffers.shift(); // == smallerBuf
4352
4012
 
4353
- /*
4354
- * Export kMaxLength after typed array support is determined.
4355
- */
4356
- kMaxLength();
4013
+ read.func.call(this, smallerBuf);
4014
+ }
4015
+ };
4357
4016
 
4358
- function kMaxLength () {
4359
- return Buffer.TYPED_ARRAY_SUPPORT
4360
- ? 0x7fffffff
4361
- : 0x3fffffff
4362
- }
4017
+ ChunkStream$2.prototype._processRead = function (read) {
4018
+ this._reads.shift(); // == read
4363
4019
 
4364
- function createBuffer (that, length) {
4365
- if (kMaxLength() < length) {
4366
- throw new RangeError('Invalid typed array length')
4367
- }
4368
- if (Buffer.TYPED_ARRAY_SUPPORT) {
4369
- // Return an augmented `Uint8Array` instance, for best performance
4370
- that = new Uint8Array(length);
4371
- that.__proto__ = Buffer.prototype;
4372
- } else {
4373
- // Fallback: Return an object instance of the Buffer class
4374
- if (that === null) {
4375
- that = new Buffer(length);
4376
- }
4377
- that.length = length;
4378
- }
4020
+ let pos = 0;
4021
+ let count = 0;
4022
+ let data = Buffer.alloc(read.length);
4379
4023
 
4380
- return that
4381
- }
4024
+ // create buffer for all data
4025
+ while (pos < read.length) {
4026
+ let buf = this._buffers[count++];
4027
+ let len = Math.min(buf.length, read.length - pos);
4382
4028
 
4383
- /**
4384
- * The Buffer constructor returns instances of `Uint8Array` that have their
4385
- * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
4386
- * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
4387
- * and the `Uint8Array` methods. Square bracket notation works as expected -- it
4388
- * returns a single octet.
4389
- *
4390
- * The `Uint8Array` prototype remains unmodified.
4391
- */
4029
+ buf.copy(data, pos, 0, len);
4030
+ pos += len;
4392
4031
 
4393
- function Buffer (arg, encodingOrOffset, length) {
4394
- if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
4395
- return new Buffer(arg, encodingOrOffset, length)
4032
+ // last buffer wasn't used all so just slice it and leave
4033
+ if (len !== buf.length) {
4034
+ this._buffers[--count] = buf.slice(len);
4035
+ }
4396
4036
  }
4397
4037
 
4398
- // Common case.
4399
- if (typeof arg === 'number') {
4400
- if (typeof encodingOrOffset === 'string') {
4401
- throw new Error(
4402
- 'If encoding is specified then the first argument must be a string'
4403
- )
4404
- }
4405
- return allocUnsafe(this, arg)
4038
+ // remove all used buffers
4039
+ if (count > 0) {
4040
+ this._buffers.splice(0, count);
4406
4041
  }
4407
- return from(this, arg, encodingOrOffset, length)
4408
- }
4409
4042
 
4410
- Buffer.poolSize = 8192; // not used by this implementation
4043
+ this._buffered -= read.length;
4411
4044
 
4412
- // TODO: Legacy, not needed anymore. Remove in next major version.
4413
- Buffer._augment = function (arr) {
4414
- arr.__proto__ = Buffer.prototype;
4415
- return arr
4045
+ read.func.call(this, data);
4416
4046
  };
4417
4047
 
4418
- function from (that, value, encodingOrOffset, length) {
4419
- if (typeof value === 'number') {
4420
- throw new TypeError('"value" argument must not be a number')
4421
- }
4422
-
4423
- if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
4424
- return fromArrayBuffer(that, value, encodingOrOffset, length)
4425
- }
4048
+ ChunkStream$2.prototype._process = function () {
4049
+ try {
4050
+ // as long as there is any data and read requests
4051
+ while (this._buffered > 0 && this._reads && this._reads.length > 0) {
4052
+ let read = this._reads[0];
4426
4053
 
4427
- if (typeof value === 'string') {
4428
- return fromString(that, value, encodingOrOffset)
4429
- }
4054
+ // read any data (but no more than length)
4055
+ if (read.allowLess) {
4056
+ this._processReadAllowingLess(read);
4057
+ } else if (this._buffered >= read.length) {
4058
+ // ok we can meet some expectations
4430
4059
 
4431
- return fromObject(that, value)
4432
- }
4060
+ this._processRead(read);
4061
+ } else {
4062
+ // not enought data to satisfy first request in queue
4063
+ // so we need to wait for more
4064
+ break;
4065
+ }
4066
+ }
4433
4067
 
4434
- /**
4435
- * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
4436
- * if value is a number.
4437
- * Buffer.from(str[, encoding])
4438
- * Buffer.from(array)
4439
- * Buffer.from(buffer)
4440
- * Buffer.from(arrayBuffer[, byteOffset[, length]])
4441
- **/
4442
- Buffer.from = function (value, encodingOrOffset, length) {
4443
- return from(null, value, encodingOrOffset, length)
4068
+ if (this._buffers && !this.writable) {
4069
+ this._end();
4070
+ }
4071
+ } catch (ex) {
4072
+ this.emit("error", ex);
4073
+ }
4444
4074
  };
4445
4075
 
4446
- if (Buffer.TYPED_ARRAY_SUPPORT) {
4447
- Buffer.prototype.__proto__ = Uint8Array.prototype;
4448
- Buffer.__proto__ = Uint8Array;
4449
- }
4076
+ var filterParseAsync = {exports: {}};
4450
4077
 
4451
- function assertSize (size) {
4452
- if (typeof size !== 'number') {
4453
- throw new TypeError('"size" argument must be a number')
4454
- } else if (size < 0) {
4455
- throw new RangeError('"size" argument must not be negative')
4456
- }
4457
- }
4078
+ var filterParse = {exports: {}};
4458
4079
 
4459
- function alloc (that, size, fill, encoding) {
4460
- assertSize(size);
4461
- if (size <= 0) {
4462
- return createBuffer(that, size)
4463
- }
4464
- if (fill !== undefined) {
4465
- // Only pay attention to encoding if it's a string. This
4466
- // prevents accidentally sending in a number that would
4467
- // be interpretted as a start offset.
4468
- return typeof encoding === 'string'
4469
- ? createBuffer(that, size).fill(fill, encoding)
4470
- : createBuffer(that, size).fill(fill)
4471
- }
4472
- return createBuffer(that, size)
4473
- }
4080
+ var interlace = {};
4474
4081
 
4475
- /**
4476
- * Creates a new filled Buffer instance.
4477
- * alloc(size[, fill[, encoding]])
4478
- **/
4479
- Buffer.alloc = function (size, fill, encoding) {
4480
- return alloc(null, size, fill, encoding)
4481
- };
4082
+ // Adam 7
4083
+ // 0 1 2 3 4 5 6 7
4084
+ // 0 x 6 4 6 x 6 4 6
4085
+ // 1 7 7 7 7 7 7 7 7
4086
+ // 2 5 6 5 6 5 6 5 6
4087
+ // 3 7 7 7 7 7 7 7 7
4088
+ // 4 3 6 4 6 3 6 4 6
4089
+ // 5 7 7 7 7 7 7 7 7
4090
+ // 6 5 6 5 6 5 6 5 6
4091
+ // 7 7 7 7 7 7 7 7 7
4092
+
4093
+ let imagePasses = [
4094
+ {
4095
+ // pass 1 - 1px
4096
+ x: [0],
4097
+ y: [0],
4098
+ },
4099
+ {
4100
+ // pass 2 - 1px
4101
+ x: [4],
4102
+ y: [0],
4103
+ },
4104
+ {
4105
+ // pass 3 - 2px
4106
+ x: [0, 4],
4107
+ y: [4],
4108
+ },
4109
+ {
4110
+ // pass 4 - 4px
4111
+ x: [2, 6],
4112
+ y: [0, 4],
4113
+ },
4114
+ {
4115
+ // pass 5 - 8px
4116
+ x: [0, 2, 4, 6],
4117
+ y: [2, 6],
4118
+ },
4119
+ {
4120
+ // pass 6 - 16px
4121
+ x: [1, 3, 5, 7],
4122
+ y: [0, 2, 4, 6],
4123
+ },
4124
+ {
4125
+ // pass 7 - 32px
4126
+ x: [0, 1, 2, 3, 4, 5, 6, 7],
4127
+ y: [1, 3, 5, 7],
4128
+ },
4129
+ ];
4482
4130
 
4483
- function allocUnsafe (that, size) {
4484
- assertSize(size);
4485
- that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
4486
- if (!Buffer.TYPED_ARRAY_SUPPORT) {
4487
- for (var i = 0; i < size; ++i) {
4488
- that[i] = 0;
4131
+ interlace.getImagePasses = function (width, height) {
4132
+ let images = [];
4133
+ let xLeftOver = width % 8;
4134
+ let yLeftOver = height % 8;
4135
+ let xRepeats = (width - xLeftOver) / 8;
4136
+ let yRepeats = (height - yLeftOver) / 8;
4137
+ for (let i = 0; i < imagePasses.length; i++) {
4138
+ let pass = imagePasses[i];
4139
+ let passWidth = xRepeats * pass.x.length;
4140
+ let passHeight = yRepeats * pass.y.length;
4141
+ for (let j = 0; j < pass.x.length; j++) {
4142
+ if (pass.x[j] < xLeftOver) {
4143
+ passWidth++;
4144
+ } else {
4145
+ break;
4146
+ }
4147
+ }
4148
+ for (let j = 0; j < pass.y.length; j++) {
4149
+ if (pass.y[j] < yLeftOver) {
4150
+ passHeight++;
4151
+ } else {
4152
+ break;
4153
+ }
4154
+ }
4155
+ if (passWidth > 0 && passHeight > 0) {
4156
+ images.push({ width: passWidth, height: passHeight, index: i });
4489
4157
  }
4490
4158
  }
4491
- return that
4492
- }
4493
-
4494
- /**
4495
- * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
4496
- * */
4497
- Buffer.allocUnsafe = function (size) {
4498
- return allocUnsafe(null, size)
4159
+ return images;
4499
4160
  };
4500
- /**
4501
- * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
4502
- */
4503
- Buffer.allocUnsafeSlow = function (size) {
4504
- return allocUnsafe(null, size)
4161
+
4162
+ interlace.getInterlaceIterator = function (width) {
4163
+ return function (x, y, pass) {
4164
+ let outerXLeftOver = x % imagePasses[pass].x.length;
4165
+ let outerX =
4166
+ ((x - outerXLeftOver) / imagePasses[pass].x.length) * 8 +
4167
+ imagePasses[pass].x[outerXLeftOver];
4168
+ let outerYLeftOver = y % imagePasses[pass].y.length;
4169
+ let outerY =
4170
+ ((y - outerYLeftOver) / imagePasses[pass].y.length) * 8 +
4171
+ imagePasses[pass].y[outerYLeftOver];
4172
+ return outerX * 4 + outerY * width * 4;
4173
+ };
4505
4174
  };
4506
4175
 
4507
- function fromString (that, string, encoding) {
4508
- if (typeof encoding !== 'string' || encoding === '') {
4509
- encoding = 'utf8';
4510
- }
4176
+ var paethPredictor$2 = function paethPredictor(left, above, upLeft) {
4177
+ let paeth = left + above - upLeft;
4178
+ let pLeft = Math.abs(paeth - left);
4179
+ let pAbove = Math.abs(paeth - above);
4180
+ let pUpLeft = Math.abs(paeth - upLeft);
4511
4181
 
4512
- if (!Buffer.isEncoding(encoding)) {
4513
- throw new TypeError('"encoding" must be a valid string encoding')
4182
+ if (pLeft <= pAbove && pLeft <= pUpLeft) {
4183
+ return left;
4514
4184
  }
4515
-
4516
- var length = byteLength(string, encoding) | 0;
4517
- that = createBuffer(that, length);
4518
-
4519
- var actual = that.write(string, encoding);
4520
-
4521
- if (actual !== length) {
4522
- // Writing a hex string, for example, that contains invalid characters will
4523
- // cause everything after the first invalid character to be ignored. (e.g.
4524
- // 'abxxcd' will be treated as 'ab')
4525
- that = that.slice(0, actual);
4185
+ if (pAbove <= pUpLeft) {
4186
+ return above;
4526
4187
  }
4188
+ return upLeft;
4189
+ };
4527
4190
 
4528
- return that
4529
- }
4191
+ let interlaceUtils$1 = interlace;
4192
+ let paethPredictor$1 = paethPredictor$2;
4530
4193
 
4531
- function fromArrayLike (that, array) {
4532
- var length = array.length < 0 ? 0 : checked(array.length) | 0;
4533
- that = createBuffer(that, length);
4534
- for (var i = 0; i < length; i += 1) {
4535
- that[i] = array[i] & 255;
4194
+ function getByteWidth(width, bpp, depth) {
4195
+ let byteWidth = width * bpp;
4196
+ if (depth !== 8) {
4197
+ byteWidth = Math.ceil(byteWidth / (8 / depth));
4536
4198
  }
4537
- return that
4199
+ return byteWidth;
4538
4200
  }
4539
4201
 
4540
- function fromArrayBuffer (that, array, byteOffset, length) {
4541
- array.byteLength; // this throws if `array` is not a valid ArrayBuffer
4542
-
4543
- if (byteOffset < 0 || array.byteLength < byteOffset) {
4544
- throw new RangeError('\'offset\' is out of bounds')
4545
- }
4202
+ let Filter$2 = (filterParse.exports = function (bitmapInfo, dependencies) {
4203
+ let width = bitmapInfo.width;
4204
+ let height = bitmapInfo.height;
4205
+ let interlace = bitmapInfo.interlace;
4206
+ let bpp = bitmapInfo.bpp;
4207
+ let depth = bitmapInfo.depth;
4546
4208
 
4547
- if (array.byteLength < byteOffset + (length || 0)) {
4548
- throw new RangeError('\'length\' is out of bounds')
4549
- }
4209
+ this.read = dependencies.read;
4210
+ this.write = dependencies.write;
4211
+ this.complete = dependencies.complete;
4550
4212
 
4551
- if (byteOffset === undefined && length === undefined) {
4552
- array = new Uint8Array(array);
4553
- } else if (length === undefined) {
4554
- array = new Uint8Array(array, byteOffset);
4213
+ this._imageIndex = 0;
4214
+ this._images = [];
4215
+ if (interlace) {
4216
+ let passes = interlaceUtils$1.getImagePasses(width, height);
4217
+ for (let i = 0; i < passes.length; i++) {
4218
+ this._images.push({
4219
+ byteWidth: getByteWidth(passes[i].width, bpp, depth),
4220
+ height: passes[i].height,
4221
+ lineIndex: 0,
4222
+ });
4223
+ }
4555
4224
  } else {
4556
- array = new Uint8Array(array, byteOffset, length);
4225
+ this._images.push({
4226
+ byteWidth: getByteWidth(width, bpp, depth),
4227
+ height: height,
4228
+ lineIndex: 0,
4229
+ });
4557
4230
  }
4558
4231
 
4559
- if (Buffer.TYPED_ARRAY_SUPPORT) {
4560
- // Return an augmented `Uint8Array` instance, for best performance
4561
- that = array;
4562
- that.__proto__ = Buffer.prototype;
4232
+ // when filtering the line we look at the pixel to the left
4233
+ // the spec also says it is done on a byte level regardless of the number of pixels
4234
+ // so if the depth is byte compatible (8 or 16) we subtract the bpp in order to compare back
4235
+ // a pixel rather than just a different byte part. However if we are sub byte, we ignore.
4236
+ if (depth === 8) {
4237
+ this._xComparison = bpp;
4238
+ } else if (depth === 16) {
4239
+ this._xComparison = bpp * 2;
4563
4240
  } else {
4564
- // Fallback: Return an object instance of the Buffer class
4565
- that = fromArrayLike(that, array);
4241
+ this._xComparison = 1;
4566
4242
  }
4567
- return that
4568
- }
4243
+ });
4569
4244
 
4570
- function fromObject (that, obj) {
4571
- if (internalIsBuffer(obj)) {
4572
- var len = checked(obj.length) | 0;
4573
- that = createBuffer(that, len);
4245
+ Filter$2.prototype.start = function () {
4246
+ this.read(
4247
+ this._images[this._imageIndex].byteWidth + 1,
4248
+ this._reverseFilterLine.bind(this)
4249
+ );
4250
+ };
4574
4251
 
4575
- if (that.length === 0) {
4576
- return that
4577
- }
4252
+ Filter$2.prototype._unFilterType1 = function (
4253
+ rawData,
4254
+ unfilteredLine,
4255
+ byteWidth
4256
+ ) {
4257
+ let xComparison = this._xComparison;
4258
+ let xBiggerThan = xComparison - 1;
4578
4259
 
4579
- obj.copy(that, 0, 0, len);
4580
- return that
4260
+ for (let x = 0; x < byteWidth; x++) {
4261
+ let rawByte = rawData[1 + x];
4262
+ let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
4263
+ unfilteredLine[x] = rawByte + f1Left;
4581
4264
  }
4265
+ };
4582
4266
 
4583
- if (obj) {
4584
- if ((typeof ArrayBuffer !== 'undefined' &&
4585
- obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
4586
- if (typeof obj.length !== 'number' || isnan(obj.length)) {
4587
- return createBuffer(that, 0)
4588
- }
4589
- return fromArrayLike(that, obj)
4590
- }
4267
+ Filter$2.prototype._unFilterType2 = function (
4268
+ rawData,
4269
+ unfilteredLine,
4270
+ byteWidth
4271
+ ) {
4272
+ let lastLine = this._lastLine;
4591
4273
 
4592
- if (obj.type === 'Buffer' && isArray(obj.data)) {
4593
- return fromArrayLike(that, obj.data)
4594
- }
4274
+ for (let x = 0; x < byteWidth; x++) {
4275
+ let rawByte = rawData[1 + x];
4276
+ let f2Up = lastLine ? lastLine[x] : 0;
4277
+ unfilteredLine[x] = rawByte + f2Up;
4595
4278
  }
4279
+ };
4596
4280
 
4597
- throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
4598
- }
4281
+ Filter$2.prototype._unFilterType3 = function (
4282
+ rawData,
4283
+ unfilteredLine,
4284
+ byteWidth
4285
+ ) {
4286
+ let xComparison = this._xComparison;
4287
+ let xBiggerThan = xComparison - 1;
4288
+ let lastLine = this._lastLine;
4599
4289
 
4600
- function checked (length) {
4601
- // Note: cannot use `length < kMaxLength()` here because that fails when
4602
- // length is NaN (which is otherwise coerced to zero.)
4603
- if (length >= kMaxLength()) {
4604
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
4605
- 'size: 0x' + kMaxLength().toString(16) + ' bytes')
4290
+ for (let x = 0; x < byteWidth; x++) {
4291
+ let rawByte = rawData[1 + x];
4292
+ let f3Up = lastLine ? lastLine[x] : 0;
4293
+ let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
4294
+ let f3Add = Math.floor((f3Left + f3Up) / 2);
4295
+ unfilteredLine[x] = rawByte + f3Add;
4606
4296
  }
4607
- return length | 0
4608
- }
4609
- Buffer.isBuffer = isBuffer;
4610
- function internalIsBuffer (b) {
4611
- return !!(b != null && b._isBuffer)
4612
- }
4297
+ };
4613
4298
 
4614
- Buffer.compare = function compare (a, b) {
4615
- if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
4616
- throw new TypeError('Arguments must be Buffers')
4617
- }
4299
+ Filter$2.prototype._unFilterType4 = function (
4300
+ rawData,
4301
+ unfilteredLine,
4302
+ byteWidth
4303
+ ) {
4304
+ let xComparison = this._xComparison;
4305
+ let xBiggerThan = xComparison - 1;
4306
+ let lastLine = this._lastLine;
4618
4307
 
4619
- if (a === b) return 0
4308
+ for (let x = 0; x < byteWidth; x++) {
4309
+ let rawByte = rawData[1 + x];
4310
+ let f4Up = lastLine ? lastLine[x] : 0;
4311
+ let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
4312
+ let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
4313
+ let f4Add = paethPredictor$1(f4Left, f4Up, f4UpLeft);
4314
+ unfilteredLine[x] = rawByte + f4Add;
4315
+ }
4316
+ };
4620
4317
 
4621
- var x = a.length;
4622
- var y = b.length;
4318
+ Filter$2.prototype._reverseFilterLine = function (rawData) {
4319
+ let filter = rawData[0];
4320
+ let unfilteredLine;
4321
+ let currentImage = this._images[this._imageIndex];
4322
+ let byteWidth = currentImage.byteWidth;
4623
4323
 
4624
- for (var i = 0, len = Math.min(x, y); i < len; ++i) {
4625
- if (a[i] !== b[i]) {
4626
- x = a[i];
4627
- y = b[i];
4628
- break
4324
+ if (filter === 0) {
4325
+ unfilteredLine = rawData.slice(1, byteWidth + 1);
4326
+ } else {
4327
+ unfilteredLine = Buffer.alloc(byteWidth);
4328
+
4329
+ switch (filter) {
4330
+ case 1:
4331
+ this._unFilterType1(rawData, unfilteredLine, byteWidth);
4332
+ break;
4333
+ case 2:
4334
+ this._unFilterType2(rawData, unfilteredLine, byteWidth);
4335
+ break;
4336
+ case 3:
4337
+ this._unFilterType3(rawData, unfilteredLine, byteWidth);
4338
+ break;
4339
+ case 4:
4340
+ this._unFilterType4(rawData, unfilteredLine, byteWidth);
4341
+ break;
4342
+ default:
4343
+ throw new Error("Unrecognised filter type - " + filter);
4629
4344
  }
4630
4345
  }
4631
4346
 
4632
- if (x < y) return -1
4633
- if (y < x) return 1
4634
- return 0
4635
- };
4347
+ this.write(unfilteredLine);
4636
4348
 
4637
- Buffer.isEncoding = function isEncoding (encoding) {
4638
- switch (String(encoding).toLowerCase()) {
4639
- case 'hex':
4640
- case 'utf8':
4641
- case 'utf-8':
4642
- case 'ascii':
4643
- case 'latin1':
4644
- case 'binary':
4645
- case 'base64':
4646
- case 'ucs2':
4647
- case 'ucs-2':
4648
- case 'utf16le':
4649
- case 'utf-16le':
4650
- return true
4651
- default:
4652
- return false
4349
+ currentImage.lineIndex++;
4350
+ if (currentImage.lineIndex >= currentImage.height) {
4351
+ this._lastLine = null;
4352
+ this._imageIndex++;
4353
+ currentImage = this._images[this._imageIndex];
4354
+ } else {
4355
+ this._lastLine = unfilteredLine;
4653
4356
  }
4654
- };
4655
4357
 
4656
- Buffer.concat = function concat (list, length) {
4657
- if (!isArray(list)) {
4658
- throw new TypeError('"list" argument must be an Array of Buffers')
4358
+ if (currentImage) {
4359
+ // read, using the byte width that may be from the new current image
4360
+ this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
4361
+ } else {
4362
+ this._lastLine = null;
4363
+ this.complete();
4659
4364
  }
4365
+ };
4660
4366
 
4661
- if (list.length === 0) {
4662
- return Buffer.alloc(0)
4663
- }
4367
+ let util$3 = require$$0__default["default"];
4368
+ let ChunkStream$1 = chunkstream.exports;
4369
+ let Filter$1 = filterParse.exports;
4664
4370
 
4665
- var i;
4666
- if (length === undefined) {
4667
- length = 0;
4668
- for (i = 0; i < list.length; ++i) {
4669
- length += list[i].length;
4670
- }
4671
- }
4371
+ let FilterAsync$1 = (filterParseAsync.exports = function (bitmapInfo) {
4372
+ ChunkStream$1.call(this);
4672
4373
 
4673
- var buffer = Buffer.allocUnsafe(length);
4674
- var pos = 0;
4675
- for (i = 0; i < list.length; ++i) {
4676
- var buf = list[i];
4677
- if (!internalIsBuffer(buf)) {
4678
- throw new TypeError('"list" argument must be an Array of Buffers')
4679
- }
4680
- buf.copy(buffer, pos);
4681
- pos += buf.length;
4682
- }
4683
- return buffer
4374
+ let buffers = [];
4375
+ let that = this;
4376
+ this._filter = new Filter$1(bitmapInfo, {
4377
+ read: this.read.bind(this),
4378
+ write: function (buffer) {
4379
+ buffers.push(buffer);
4380
+ },
4381
+ complete: function () {
4382
+ that.emit("complete", Buffer.concat(buffers));
4383
+ },
4384
+ });
4385
+
4386
+ this._filter.start();
4387
+ });
4388
+ util$3.inherits(FilterAsync$1, ChunkStream$1);
4389
+
4390
+ var parser = {exports: {}};
4391
+
4392
+ var constants$5 = {
4393
+ PNG_SIGNATURE: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a],
4394
+
4395
+ TYPE_IHDR: 0x49484452,
4396
+ TYPE_IEND: 0x49454e44,
4397
+ TYPE_IDAT: 0x49444154,
4398
+ TYPE_PLTE: 0x504c5445,
4399
+ TYPE_tRNS: 0x74524e53, // eslint-disable-line camelcase
4400
+ TYPE_gAMA: 0x67414d41, // eslint-disable-line camelcase
4401
+
4402
+ // color-type bits
4403
+ COLORTYPE_GRAYSCALE: 0,
4404
+ COLORTYPE_PALETTE: 1,
4405
+ COLORTYPE_COLOR: 2,
4406
+ COLORTYPE_ALPHA: 4, // e.g. grayscale and alpha
4407
+
4408
+ // color-type combinations
4409
+ COLORTYPE_PALETTE_COLOR: 3,
4410
+ COLORTYPE_COLOR_ALPHA: 6,
4411
+
4412
+ COLORTYPE_TO_BPP_MAP: {
4413
+ 0: 1,
4414
+ 2: 3,
4415
+ 3: 1,
4416
+ 4: 2,
4417
+ 6: 4,
4418
+ },
4419
+
4420
+ GAMMA_DIVISION: 100000,
4684
4421
  };
4685
4422
 
4686
- function byteLength (string, encoding) {
4687
- if (internalIsBuffer(string)) {
4688
- return string.length
4689
- }
4690
- if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
4691
- (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
4692
- return string.byteLength
4693
- }
4694
- if (typeof string !== 'string') {
4695
- string = '' + string;
4696
- }
4423
+ var crc = {exports: {}};
4697
4424
 
4698
- var len = string.length;
4699
- if (len === 0) return 0
4425
+ let crcTable = [];
4700
4426
 
4701
- // Use a for loop to avoid recursion
4702
- var loweredCase = false;
4703
- for (;;) {
4704
- switch (encoding) {
4705
- case 'ascii':
4706
- case 'latin1':
4707
- case 'binary':
4708
- return len
4709
- case 'utf8':
4710
- case 'utf-8':
4711
- case undefined:
4712
- return utf8ToBytes(string).length
4713
- case 'ucs2':
4714
- case 'ucs-2':
4715
- case 'utf16le':
4716
- case 'utf-16le':
4717
- return len * 2
4718
- case 'hex':
4719
- return len >>> 1
4720
- case 'base64':
4721
- return base64ToBytes(string).length
4722
- default:
4723
- if (loweredCase) return utf8ToBytes(string).length // assume utf8
4724
- encoding = ('' + encoding).toLowerCase();
4725
- loweredCase = true;
4427
+ (function () {
4428
+ for (let i = 0; i < 256; i++) {
4429
+ let currentCrc = i;
4430
+ for (let j = 0; j < 8; j++) {
4431
+ if (currentCrc & 1) {
4432
+ currentCrc = 0xedb88320 ^ (currentCrc >>> 1);
4433
+ } else {
4434
+ currentCrc = currentCrc >>> 1;
4435
+ }
4726
4436
  }
4437
+ crcTable[i] = currentCrc;
4727
4438
  }
4728
- }
4729
- Buffer.byteLength = byteLength;
4730
-
4731
- function slowToString (encoding, start, end) {
4732
- var loweredCase = false;
4439
+ })();
4733
4440
 
4734
- // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
4735
- // property of a typed array.
4441
+ let CrcCalculator$1 = (crc.exports = function () {
4442
+ this._crc = -1;
4443
+ });
4736
4444
 
4737
- // This behaves neither like String nor Uint8Array in that we set start/end
4738
- // to their upper/lower bounds if the value passed is out of range.
4739
- // undefined is handled specially as per ECMA-262 6th Edition,
4740
- // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
4741
- if (start === undefined || start < 0) {
4742
- start = 0;
4743
- }
4744
- // Return early if start > this.length. Done here to prevent potential uint32
4745
- // coercion fail below.
4746
- if (start > this.length) {
4747
- return ''
4445
+ CrcCalculator$1.prototype.write = function (data) {
4446
+ for (let i = 0; i < data.length; i++) {
4447
+ this._crc = crcTable[(this._crc ^ data[i]) & 0xff] ^ (this._crc >>> 8);
4748
4448
  }
4449
+ return true;
4450
+ };
4749
4451
 
4750
- if (end === undefined || end > this.length) {
4751
- end = this.length;
4752
- }
4452
+ CrcCalculator$1.prototype.crc32 = function () {
4453
+ return this._crc ^ -1;
4454
+ };
4753
4455
 
4754
- if (end <= 0) {
4755
- return ''
4456
+ CrcCalculator$1.crc32 = function (buf) {
4457
+ let crc = -1;
4458
+ for (let i = 0; i < buf.length; i++) {
4459
+ crc = crcTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
4756
4460
  }
4461
+ return crc ^ -1;
4462
+ };
4757
4463
 
4758
- // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
4759
- end >>>= 0;
4760
- start >>>= 0;
4761
-
4762
- if (end <= start) {
4763
- return ''
4764
- }
4464
+ let constants$4 = constants$5;
4465
+ let CrcCalculator = crc.exports;
4765
4466
 
4766
- if (!encoding) encoding = 'utf8';
4467
+ let Parser$3 = (parser.exports = function (options, dependencies) {
4468
+ this._options = options;
4469
+ options.checkCRC = options.checkCRC !== false;
4767
4470
 
4768
- while (true) {
4769
- switch (encoding) {
4770
- case 'hex':
4771
- return hexSlice(this, start, end)
4471
+ this._hasIHDR = false;
4472
+ this._hasIEND = false;
4473
+ this._emittedHeadersFinished = false;
4772
4474
 
4773
- case 'utf8':
4774
- case 'utf-8':
4775
- return utf8Slice(this, start, end)
4475
+ // input flags/metadata
4476
+ this._palette = [];
4477
+ this._colorType = 0;
4776
4478
 
4777
- case 'ascii':
4778
- return asciiSlice(this, start, end)
4479
+ this._chunks = {};
4480
+ this._chunks[constants$4.TYPE_IHDR] = this._handleIHDR.bind(this);
4481
+ this._chunks[constants$4.TYPE_IEND] = this._handleIEND.bind(this);
4482
+ this._chunks[constants$4.TYPE_IDAT] = this._handleIDAT.bind(this);
4483
+ this._chunks[constants$4.TYPE_PLTE] = this._handlePLTE.bind(this);
4484
+ this._chunks[constants$4.TYPE_tRNS] = this._handleTRNS.bind(this);
4485
+ this._chunks[constants$4.TYPE_gAMA] = this._handleGAMA.bind(this);
4779
4486
 
4780
- case 'latin1':
4781
- case 'binary':
4782
- return latin1Slice(this, start, end)
4487
+ this.read = dependencies.read;
4488
+ this.error = dependencies.error;
4489
+ this.metadata = dependencies.metadata;
4490
+ this.gamma = dependencies.gamma;
4491
+ this.transColor = dependencies.transColor;
4492
+ this.palette = dependencies.palette;
4493
+ this.parsed = dependencies.parsed;
4494
+ this.inflateData = dependencies.inflateData;
4495
+ this.finished = dependencies.finished;
4496
+ this.simpleTransparency = dependencies.simpleTransparency;
4497
+ this.headersFinished = dependencies.headersFinished || function () {};
4498
+ });
4783
4499
 
4784
- case 'base64':
4785
- return base64Slice(this, start, end)
4500
+ Parser$3.prototype.start = function () {
4501
+ this.read(constants$4.PNG_SIGNATURE.length, this._parseSignature.bind(this));
4502
+ };
4786
4503
 
4787
- case 'ucs2':
4788
- case 'ucs-2':
4789
- case 'utf16le':
4790
- case 'utf-16le':
4791
- return utf16leSlice(this, start, end)
4504
+ Parser$3.prototype._parseSignature = function (data) {
4505
+ let signature = constants$4.PNG_SIGNATURE;
4792
4506
 
4793
- default:
4794
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
4795
- encoding = (encoding + '').toLowerCase();
4796
- loweredCase = true;
4507
+ for (let i = 0; i < signature.length; i++) {
4508
+ if (data[i] !== signature[i]) {
4509
+ this.error(new Error("Invalid file signature"));
4510
+ return;
4797
4511
  }
4798
4512
  }
4799
- }
4800
-
4801
- // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
4802
- // Buffer instances.
4803
- Buffer.prototype._isBuffer = true;
4513
+ this.read(8, this._parseChunkBegin.bind(this));
4514
+ };
4804
4515
 
4805
- function swap (b, n, m) {
4806
- var i = b[n];
4807
- b[n] = b[m];
4808
- b[m] = i;
4809
- }
4516
+ Parser$3.prototype._parseChunkBegin = function (data) {
4517
+ // chunk content length
4518
+ let length = data.readUInt32BE(0);
4810
4519
 
4811
- Buffer.prototype.swap16 = function swap16 () {
4812
- var len = this.length;
4813
- if (len % 2 !== 0) {
4814
- throw new RangeError('Buffer size must be a multiple of 16-bits')
4520
+ // chunk type
4521
+ let type = data.readUInt32BE(4);
4522
+ let name = "";
4523
+ for (let i = 4; i < 8; i++) {
4524
+ name += String.fromCharCode(data[i]);
4815
4525
  }
4816
- for (var i = 0; i < len; i += 2) {
4817
- swap(this, i, i + 1);
4818
- }
4819
- return this
4820
- };
4821
4526
 
4822
- Buffer.prototype.swap32 = function swap32 () {
4823
- var len = this.length;
4824
- if (len % 4 !== 0) {
4825
- throw new RangeError('Buffer size must be a multiple of 32-bits')
4826
- }
4827
- for (var i = 0; i < len; i += 4) {
4828
- swap(this, i, i + 3);
4829
- swap(this, i + 1, i + 2);
4527
+ //console.log('chunk ', name, length);
4528
+
4529
+ // chunk flags
4530
+ let ancillary = Boolean(data[4] & 0x20); // or critical
4531
+ // priv = Boolean(data[5] & 0x20), // or public
4532
+ // safeToCopy = Boolean(data[7] & 0x20); // or unsafe
4533
+
4534
+ if (!this._hasIHDR && type !== constants$4.TYPE_IHDR) {
4535
+ this.error(new Error("Expected IHDR on beggining"));
4536
+ return;
4830
4537
  }
4831
- return this
4832
- };
4833
4538
 
4834
- Buffer.prototype.swap64 = function swap64 () {
4835
- var len = this.length;
4836
- if (len % 8 !== 0) {
4837
- throw new RangeError('Buffer size must be a multiple of 64-bits')
4539
+ this._crc = new CrcCalculator();
4540
+ this._crc.write(Buffer.from(name));
4541
+
4542
+ if (this._chunks[type]) {
4543
+ return this._chunks[type](length);
4838
4544
  }
4839
- for (var i = 0; i < len; i += 8) {
4840
- swap(this, i, i + 7);
4841
- swap(this, i + 1, i + 6);
4842
- swap(this, i + 2, i + 5);
4843
- swap(this, i + 3, i + 4);
4545
+
4546
+ if (!ancillary) {
4547
+ this.error(new Error("Unsupported critical chunk type " + name));
4548
+ return;
4844
4549
  }
4845
- return this
4846
- };
4847
4550
 
4848
- Buffer.prototype.toString = function toString () {
4849
- var length = this.length | 0;
4850
- if (length === 0) return ''
4851
- if (arguments.length === 0) return utf8Slice(this, 0, length)
4852
- return slowToString.apply(this, arguments)
4551
+ this.read(length + 4, this._skipChunk.bind(this));
4853
4552
  };
4854
4553
 
4855
- Buffer.prototype.equals = function equals (b) {
4856
- if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
4857
- if (this === b) return true
4858
- return Buffer.compare(this, b) === 0
4554
+ Parser$3.prototype._skipChunk = function (/*data*/) {
4555
+ this.read(8, this._parseChunkBegin.bind(this));
4859
4556
  };
4860
4557
 
4861
- Buffer.prototype.inspect = function inspect () {
4862
- var str = '';
4863
- var max = INSPECT_MAX_BYTES;
4864
- if (this.length > 0) {
4865
- str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
4866
- if (this.length > max) str += ' ... ';
4867
- }
4868
- return '<Buffer ' + str + '>'
4558
+ Parser$3.prototype._handleChunkEnd = function () {
4559
+ this.read(4, this._parseChunkEnd.bind(this));
4869
4560
  };
4870
4561
 
4871
- Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
4872
- if (!internalIsBuffer(target)) {
4873
- throw new TypeError('Argument must be a Buffer')
4874
- }
4562
+ Parser$3.prototype._parseChunkEnd = function (data) {
4563
+ let fileCrc = data.readInt32BE(0);
4564
+ let calcCrc = this._crc.crc32();
4875
4565
 
4876
- if (start === undefined) {
4877
- start = 0;
4878
- }
4879
- if (end === undefined) {
4880
- end = target ? target.length : 0;
4881
- }
4882
- if (thisStart === undefined) {
4883
- thisStart = 0;
4884
- }
4885
- if (thisEnd === undefined) {
4886
- thisEnd = this.length;
4566
+ // check CRC
4567
+ if (this._options.checkCRC && calcCrc !== fileCrc) {
4568
+ this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
4569
+ return;
4887
4570
  }
4888
4571
 
4889
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
4890
- throw new RangeError('out of range index')
4572
+ if (!this._hasIEND) {
4573
+ this.read(8, this._parseChunkBegin.bind(this));
4891
4574
  }
4575
+ };
4892
4576
 
4893
- if (thisStart >= thisEnd && start >= end) {
4894
- return 0
4895
- }
4896
- if (thisStart >= thisEnd) {
4897
- return -1
4898
- }
4899
- if (start >= end) {
4900
- return 1
4577
+ Parser$3.prototype._handleIHDR = function (length) {
4578
+ this.read(length, this._parseIHDR.bind(this));
4579
+ };
4580
+ Parser$3.prototype._parseIHDR = function (data) {
4581
+ this._crc.write(data);
4582
+
4583
+ let width = data.readUInt32BE(0);
4584
+ let height = data.readUInt32BE(4);
4585
+ let depth = data[8];
4586
+ let colorType = data[9]; // bits: 1 palette, 2 color, 4 alpha
4587
+ let compr = data[10];
4588
+ let filter = data[11];
4589
+ let interlace = data[12];
4590
+
4591
+ // console.log(' width', width, 'height', height,
4592
+ // 'depth', depth, 'colorType', colorType,
4593
+ // 'compr', compr, 'filter', filter, 'interlace', interlace
4594
+ // );
4595
+
4596
+ if (
4597
+ depth !== 8 &&
4598
+ depth !== 4 &&
4599
+ depth !== 2 &&
4600
+ depth !== 1 &&
4601
+ depth !== 16
4602
+ ) {
4603
+ this.error(new Error("Unsupported bit depth " + depth));
4604
+ return;
4605
+ }
4606
+ if (!(colorType in constants$4.COLORTYPE_TO_BPP_MAP)) {
4607
+ this.error(new Error("Unsupported color type"));
4608
+ return;
4609
+ }
4610
+ if (compr !== 0) {
4611
+ this.error(new Error("Unsupported compression method"));
4612
+ return;
4613
+ }
4614
+ if (filter !== 0) {
4615
+ this.error(new Error("Unsupported filter method"));
4616
+ return;
4617
+ }
4618
+ if (interlace !== 0 && interlace !== 1) {
4619
+ this.error(new Error("Unsupported interlace method"));
4620
+ return;
4901
4621
  }
4902
4622
 
4903
- start >>>= 0;
4904
- end >>>= 0;
4905
- thisStart >>>= 0;
4906
- thisEnd >>>= 0;
4623
+ this._colorType = colorType;
4907
4624
 
4908
- if (this === target) return 0
4625
+ let bpp = constants$4.COLORTYPE_TO_BPP_MAP[this._colorType];
4909
4626
 
4910
- var x = thisEnd - thisStart;
4911
- var y = end - start;
4912
- var len = Math.min(x, y);
4627
+ this._hasIHDR = true;
4913
4628
 
4914
- var thisCopy = this.slice(thisStart, thisEnd);
4915
- var targetCopy = target.slice(start, end);
4629
+ this.metadata({
4630
+ width: width,
4631
+ height: height,
4632
+ depth: depth,
4633
+ interlace: Boolean(interlace),
4634
+ palette: Boolean(colorType & constants$4.COLORTYPE_PALETTE),
4635
+ color: Boolean(colorType & constants$4.COLORTYPE_COLOR),
4636
+ alpha: Boolean(colorType & constants$4.COLORTYPE_ALPHA),
4637
+ bpp: bpp,
4638
+ colorType: colorType,
4639
+ });
4916
4640
 
4917
- for (var i = 0; i < len; ++i) {
4918
- if (thisCopy[i] !== targetCopy[i]) {
4919
- x = thisCopy[i];
4920
- y = targetCopy[i];
4921
- break
4922
- }
4923
- }
4641
+ this._handleChunkEnd();
4642
+ };
4924
4643
 
4925
- if (x < y) return -1
4926
- if (y < x) return 1
4927
- return 0
4644
+ Parser$3.prototype._handlePLTE = function (length) {
4645
+ this.read(length, this._parsePLTE.bind(this));
4928
4646
  };
4647
+ Parser$3.prototype._parsePLTE = function (data) {
4648
+ this._crc.write(data);
4929
4649
 
4930
- // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
4931
- // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
4932
- //
4933
- // Arguments:
4934
- // - buffer - a Buffer to search
4935
- // - val - a string, Buffer, or number
4936
- // - byteOffset - an index into `buffer`; will be clamped to an int32
4937
- // - encoding - an optional encoding, relevant is val is a string
4938
- // - dir - true for indexOf, false for lastIndexOf
4939
- function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
4940
- // Empty buffer means no match
4941
- if (buffer.length === 0) return -1
4942
-
4943
- // Normalize byteOffset
4944
- if (typeof byteOffset === 'string') {
4945
- encoding = byteOffset;
4946
- byteOffset = 0;
4947
- } else if (byteOffset > 0x7fffffff) {
4948
- byteOffset = 0x7fffffff;
4949
- } else if (byteOffset < -0x80000000) {
4950
- byteOffset = -0x80000000;
4951
- }
4952
- byteOffset = +byteOffset; // Coerce to Number.
4953
- if (isNaN(byteOffset)) {
4954
- // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
4955
- byteOffset = dir ? 0 : (buffer.length - 1);
4956
- }
4957
-
4958
- // Normalize byteOffset: negative offsets start from the end of the buffer
4959
- if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
4960
- if (byteOffset >= buffer.length) {
4961
- if (dir) return -1
4962
- else byteOffset = buffer.length - 1;
4963
- } else if (byteOffset < 0) {
4964
- if (dir) byteOffset = 0;
4965
- else return -1
4966
- }
4967
-
4968
- // Normalize val
4969
- if (typeof val === 'string') {
4970
- val = Buffer.from(val, encoding);
4971
- }
4972
-
4973
- // Finally, search either indexOf (if dir is true) or lastIndexOf
4974
- if (internalIsBuffer(val)) {
4975
- // Special case: looking for empty string/buffer always fails
4976
- if (val.length === 0) {
4977
- return -1
4978
- }
4979
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
4980
- } else if (typeof val === 'number') {
4981
- val = val & 0xFF; // Search for a byte value [0-255]
4982
- if (Buffer.TYPED_ARRAY_SUPPORT &&
4983
- typeof Uint8Array.prototype.indexOf === 'function') {
4984
- if (dir) {
4985
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
4986
- } else {
4987
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
4988
- }
4989
- }
4990
- return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
4650
+ let entries = Math.floor(data.length / 3);
4651
+ // console.log('Palette:', entries);
4652
+
4653
+ for (let i = 0; i < entries; i++) {
4654
+ this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 0xff]);
4991
4655
  }
4992
4656
 
4993
- throw new TypeError('val must be string, number or Buffer')
4994
- }
4657
+ this.palette(this._palette);
4995
4658
 
4996
- function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
4997
- var indexSize = 1;
4998
- var arrLength = arr.length;
4999
- var valLength = val.length;
4659
+ this._handleChunkEnd();
4660
+ };
5000
4661
 
5001
- if (encoding !== undefined) {
5002
- encoding = String(encoding).toLowerCase();
5003
- if (encoding === 'ucs2' || encoding === 'ucs-2' ||
5004
- encoding === 'utf16le' || encoding === 'utf-16le') {
5005
- if (arr.length < 2 || val.length < 2) {
5006
- return -1
5007
- }
5008
- indexSize = 2;
5009
- arrLength /= 2;
5010
- valLength /= 2;
5011
- byteOffset /= 2;
5012
- }
5013
- }
4662
+ Parser$3.prototype._handleTRNS = function (length) {
4663
+ this.simpleTransparency();
4664
+ this.read(length, this._parseTRNS.bind(this));
4665
+ };
4666
+ Parser$3.prototype._parseTRNS = function (data) {
4667
+ this._crc.write(data);
5014
4668
 
5015
- function read (buf, i) {
5016
- if (indexSize === 1) {
5017
- return buf[i]
5018
- } else {
5019
- return buf.readUInt16BE(i * indexSize)
4669
+ // palette
4670
+ if (this._colorType === constants$4.COLORTYPE_PALETTE_COLOR) {
4671
+ if (this._palette.length === 0) {
4672
+ this.error(new Error("Transparency chunk must be after palette"));
4673
+ return;
5020
4674
  }
5021
- }
5022
-
5023
- var i;
5024
- if (dir) {
5025
- var foundIndex = -1;
5026
- for (i = byteOffset; i < arrLength; i++) {
5027
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
5028
- if (foundIndex === -1) foundIndex = i;
5029
- if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
5030
- } else {
5031
- if (foundIndex !== -1) i -= i - foundIndex;
5032
- foundIndex = -1;
5033
- }
4675
+ if (data.length > this._palette.length) {
4676
+ this.error(new Error("More transparent colors than palette size"));
4677
+ return;
5034
4678
  }
5035
- } else {
5036
- if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
5037
- for (i = byteOffset; i >= 0; i--) {
5038
- var found = true;
5039
- for (var j = 0; j < valLength; j++) {
5040
- if (read(arr, i + j) !== read(val, j)) {
5041
- found = false;
5042
- break
5043
- }
5044
- }
5045
- if (found) return i
4679
+ for (let i = 0; i < data.length; i++) {
4680
+ this._palette[i][3] = data[i];
5046
4681
  }
4682
+ this.palette(this._palette);
5047
4683
  }
5048
4684
 
5049
- return -1
5050
- }
4685
+ // for colorType 0 (grayscale) and 2 (rgb)
4686
+ // there might be one gray/color defined as transparent
4687
+ if (this._colorType === constants$4.COLORTYPE_GRAYSCALE) {
4688
+ // grey, 2 bytes
4689
+ this.transColor([data.readUInt16BE(0)]);
4690
+ }
4691
+ if (this._colorType === constants$4.COLORTYPE_COLOR) {
4692
+ this.transColor([
4693
+ data.readUInt16BE(0),
4694
+ data.readUInt16BE(2),
4695
+ data.readUInt16BE(4),
4696
+ ]);
4697
+ }
4698
+
4699
+ this._handleChunkEnd();
4700
+ };
5051
4701
 
5052
- Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
5053
- return this.indexOf(val, byteOffset, encoding) !== -1
4702
+ Parser$3.prototype._handleGAMA = function (length) {
4703
+ this.read(length, this._parseGAMA.bind(this));
5054
4704
  };
4705
+ Parser$3.prototype._parseGAMA = function (data) {
4706
+ this._crc.write(data);
4707
+ this.gamma(data.readUInt32BE(0) / constants$4.GAMMA_DIVISION);
5055
4708
 
5056
- Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
5057
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
4709
+ this._handleChunkEnd();
5058
4710
  };
5059
4711
 
5060
- Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
5061
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
4712
+ Parser$3.prototype._handleIDAT = function (length) {
4713
+ if (!this._emittedHeadersFinished) {
4714
+ this._emittedHeadersFinished = true;
4715
+ this.headersFinished();
4716
+ }
4717
+ this.read(-length, this._parseIDAT.bind(this, length));
5062
4718
  };
4719
+ Parser$3.prototype._parseIDAT = function (length, data) {
4720
+ this._crc.write(data);
5063
4721
 
5064
- function hexWrite (buf, string, offset, length) {
5065
- offset = Number(offset) || 0;
5066
- var remaining = buf.length - offset;
5067
- if (!length) {
5068
- length = remaining;
4722
+ if (
4723
+ this._colorType === constants$4.COLORTYPE_PALETTE_COLOR &&
4724
+ this._palette.length === 0
4725
+ ) {
4726
+ throw new Error("Expected palette not found");
4727
+ }
4728
+
4729
+ this.inflateData(data);
4730
+ let leftOverLength = length - data.length;
4731
+
4732
+ if (leftOverLength > 0) {
4733
+ this._handleIDAT(leftOverLength);
5069
4734
  } else {
5070
- length = Number(length);
5071
- if (length > remaining) {
5072
- length = remaining;
5073
- }
4735
+ this._handleChunkEnd();
5074
4736
  }
4737
+ };
4738
+
4739
+ Parser$3.prototype._handleIEND = function (length) {
4740
+ this.read(length, this._parseIEND.bind(this));
4741
+ };
4742
+ Parser$3.prototype._parseIEND = function (data) {
4743
+ this._crc.write(data);
5075
4744
 
5076
- // must be an even number of digits
5077
- var strLen = string.length;
5078
- if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
4745
+ this._hasIEND = true;
4746
+ this._handleChunkEnd();
5079
4747
 
5080
- if (length > strLen / 2) {
5081
- length = strLen / 2;
4748
+ if (this.finished) {
4749
+ this.finished();
5082
4750
  }
5083
- for (var i = 0; i < length; ++i) {
5084
- var parsed = parseInt(string.substr(i * 2, 2), 16);
5085
- if (isNaN(parsed)) return i
5086
- buf[offset + i] = parsed;
4751
+ };
4752
+
4753
+ var bitmapper$2 = {};
4754
+
4755
+ let interlaceUtils = interlace;
4756
+
4757
+ let pixelBppMapper = [
4758
+ // 0 - dummy entry
4759
+ function () {},
4760
+
4761
+ // 1 - L
4762
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
4763
+ function (pxData, data, pxPos, rawPos) {
4764
+ if (rawPos === data.length) {
4765
+ throw new Error("Ran out of data");
4766
+ }
4767
+
4768
+ let pixel = data[rawPos];
4769
+ pxData[pxPos] = pixel;
4770
+ pxData[pxPos + 1] = pixel;
4771
+ pxData[pxPos + 2] = pixel;
4772
+ pxData[pxPos + 3] = 0xff;
4773
+ },
4774
+
4775
+ // 2 - LA
4776
+ // 0: 0, 1: 0, 2: 0, 3: 1
4777
+ function (pxData, data, pxPos, rawPos) {
4778
+ if (rawPos + 1 >= data.length) {
4779
+ throw new Error("Ran out of data");
4780
+ }
4781
+
4782
+ let pixel = data[rawPos];
4783
+ pxData[pxPos] = pixel;
4784
+ pxData[pxPos + 1] = pixel;
4785
+ pxData[pxPos + 2] = pixel;
4786
+ pxData[pxPos + 3] = data[rawPos + 1];
4787
+ },
4788
+
4789
+ // 3 - RGB
4790
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
4791
+ function (pxData, data, pxPos, rawPos) {
4792
+ if (rawPos + 2 >= data.length) {
4793
+ throw new Error("Ran out of data");
4794
+ }
4795
+
4796
+ pxData[pxPos] = data[rawPos];
4797
+ pxData[pxPos + 1] = data[rawPos + 1];
4798
+ pxData[pxPos + 2] = data[rawPos + 2];
4799
+ pxData[pxPos + 3] = 0xff;
4800
+ },
4801
+
4802
+ // 4 - RGBA
4803
+ // 0: 0, 1: 1, 2: 2, 3: 3
4804
+ function (pxData, data, pxPos, rawPos) {
4805
+ if (rawPos + 3 >= data.length) {
4806
+ throw new Error("Ran out of data");
4807
+ }
4808
+
4809
+ pxData[pxPos] = data[rawPos];
4810
+ pxData[pxPos + 1] = data[rawPos + 1];
4811
+ pxData[pxPos + 2] = data[rawPos + 2];
4812
+ pxData[pxPos + 3] = data[rawPos + 3];
4813
+ },
4814
+ ];
4815
+
4816
+ let pixelBppCustomMapper = [
4817
+ // 0 - dummy entry
4818
+ function () {},
4819
+
4820
+ // 1 - L
4821
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
4822
+ function (pxData, pixelData, pxPos, maxBit) {
4823
+ let pixel = pixelData[0];
4824
+ pxData[pxPos] = pixel;
4825
+ pxData[pxPos + 1] = pixel;
4826
+ pxData[pxPos + 2] = pixel;
4827
+ pxData[pxPos + 3] = maxBit;
4828
+ },
4829
+
4830
+ // 2 - LA
4831
+ // 0: 0, 1: 0, 2: 0, 3: 1
4832
+ function (pxData, pixelData, pxPos) {
4833
+ let pixel = pixelData[0];
4834
+ pxData[pxPos] = pixel;
4835
+ pxData[pxPos + 1] = pixel;
4836
+ pxData[pxPos + 2] = pixel;
4837
+ pxData[pxPos + 3] = pixelData[1];
4838
+ },
4839
+
4840
+ // 3 - RGB
4841
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
4842
+ function (pxData, pixelData, pxPos, maxBit) {
4843
+ pxData[pxPos] = pixelData[0];
4844
+ pxData[pxPos + 1] = pixelData[1];
4845
+ pxData[pxPos + 2] = pixelData[2];
4846
+ pxData[pxPos + 3] = maxBit;
4847
+ },
4848
+
4849
+ // 4 - RGBA
4850
+ // 0: 0, 1: 1, 2: 2, 3: 3
4851
+ function (pxData, pixelData, pxPos) {
4852
+ pxData[pxPos] = pixelData[0];
4853
+ pxData[pxPos + 1] = pixelData[1];
4854
+ pxData[pxPos + 2] = pixelData[2];
4855
+ pxData[pxPos + 3] = pixelData[3];
4856
+ },
4857
+ ];
4858
+
4859
+ function bitRetriever(data, depth) {
4860
+ let leftOver = [];
4861
+ let i = 0;
4862
+
4863
+ function split() {
4864
+ if (i === data.length) {
4865
+ throw new Error("Ran out of data");
4866
+ }
4867
+ let byte = data[i];
4868
+ i++;
4869
+ let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
4870
+ switch (depth) {
4871
+ default:
4872
+ throw new Error("unrecognised depth");
4873
+ case 16:
4874
+ byte2 = data[i];
4875
+ i++;
4876
+ leftOver.push((byte << 8) + byte2);
4877
+ break;
4878
+ case 4:
4879
+ byte2 = byte & 0x0f;
4880
+ byte1 = byte >> 4;
4881
+ leftOver.push(byte1, byte2);
4882
+ break;
4883
+ case 2:
4884
+ byte4 = byte & 3;
4885
+ byte3 = (byte >> 2) & 3;
4886
+ byte2 = (byte >> 4) & 3;
4887
+ byte1 = (byte >> 6) & 3;
4888
+ leftOver.push(byte1, byte2, byte3, byte4);
4889
+ break;
4890
+ case 1:
4891
+ byte8 = byte & 1;
4892
+ byte7 = (byte >> 1) & 1;
4893
+ byte6 = (byte >> 2) & 1;
4894
+ byte5 = (byte >> 3) & 1;
4895
+ byte4 = (byte >> 4) & 1;
4896
+ byte3 = (byte >> 5) & 1;
4897
+ byte2 = (byte >> 6) & 1;
4898
+ byte1 = (byte >> 7) & 1;
4899
+ leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
4900
+ break;
4901
+ }
5087
4902
  }
5088
- return i
5089
- }
5090
4903
 
5091
- function utf8Write (buf, string, offset, length) {
5092
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
4904
+ return {
4905
+ get: function (count) {
4906
+ while (leftOver.length < count) {
4907
+ split();
4908
+ }
4909
+ let returner = leftOver.slice(0, count);
4910
+ leftOver = leftOver.slice(count);
4911
+ return returner;
4912
+ },
4913
+ resetAfterLine: function () {
4914
+ leftOver.length = 0;
4915
+ },
4916
+ end: function () {
4917
+ if (i !== data.length) {
4918
+ throw new Error("extra data found");
4919
+ }
4920
+ },
4921
+ };
5093
4922
  }
5094
4923
 
5095
- function asciiWrite (buf, string, offset, length) {
5096
- return blitBuffer(asciiToBytes(string), buf, offset, length)
4924
+ function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
4925
+ // eslint-disable-line max-params
4926
+ let imageWidth = image.width;
4927
+ let imageHeight = image.height;
4928
+ let imagePass = image.index;
4929
+ for (let y = 0; y < imageHeight; y++) {
4930
+ for (let x = 0; x < imageWidth; x++) {
4931
+ let pxPos = getPxPos(x, y, imagePass);
4932
+ pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
4933
+ rawPos += bpp; //eslint-disable-line no-param-reassign
4934
+ }
4935
+ }
4936
+ return rawPos;
5097
4937
  }
5098
4938
 
5099
- function latin1Write (buf, string, offset, length) {
5100
- return asciiWrite(buf, string, offset, length)
4939
+ function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
4940
+ // eslint-disable-line max-params
4941
+ let imageWidth = image.width;
4942
+ let imageHeight = image.height;
4943
+ let imagePass = image.index;
4944
+ for (let y = 0; y < imageHeight; y++) {
4945
+ for (let x = 0; x < imageWidth; x++) {
4946
+ let pixelData = bits.get(bpp);
4947
+ let pxPos = getPxPos(x, y, imagePass);
4948
+ pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
4949
+ }
4950
+ bits.resetAfterLine();
4951
+ }
5101
4952
  }
5102
4953
 
5103
- function base64Write (buf, string, offset, length) {
5104
- return blitBuffer(base64ToBytes(string), buf, offset, length)
5105
- }
4954
+ bitmapper$2.dataToBitMap = function (data, bitmapInfo) {
4955
+ let width = bitmapInfo.width;
4956
+ let height = bitmapInfo.height;
4957
+ let depth = bitmapInfo.depth;
4958
+ let bpp = bitmapInfo.bpp;
4959
+ let interlace = bitmapInfo.interlace;
4960
+ let bits;
5106
4961
 
5107
- function ucs2Write (buf, string, offset, length) {
5108
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
5109
- }
4962
+ if (depth !== 8) {
4963
+ bits = bitRetriever(data, depth);
4964
+ }
4965
+ let pxData;
4966
+ if (depth <= 8) {
4967
+ pxData = Buffer.alloc(width * height * 4);
4968
+ } else {
4969
+ pxData = new Uint16Array(width * height * 4);
4970
+ }
4971
+ let maxBit = Math.pow(2, depth) - 1;
4972
+ let rawPos = 0;
4973
+ let images;
4974
+ let getPxPos;
5110
4975
 
5111
- Buffer.prototype.write = function write (string, offset, length, encoding) {
5112
- // Buffer#write(string)
5113
- if (offset === undefined) {
5114
- encoding = 'utf8';
5115
- length = this.length;
5116
- offset = 0;
5117
- // Buffer#write(string, encoding)
5118
- } else if (length === undefined && typeof offset === 'string') {
5119
- encoding = offset;
5120
- length = this.length;
5121
- offset = 0;
5122
- // Buffer#write(string, offset[, length][, encoding])
5123
- } else if (isFinite(offset)) {
5124
- offset = offset | 0;
5125
- if (isFinite(length)) {
5126
- length = length | 0;
5127
- if (encoding === undefined) encoding = 'utf8';
4976
+ if (interlace) {
4977
+ images = interlaceUtils.getImagePasses(width, height);
4978
+ getPxPos = interlaceUtils.getInterlaceIterator(width, height);
4979
+ } else {
4980
+ let nonInterlacedPxPos = 0;
4981
+ getPxPos = function () {
4982
+ let returner = nonInterlacedPxPos;
4983
+ nonInterlacedPxPos += 4;
4984
+ return returner;
4985
+ };
4986
+ images = [{ width: width, height: height }];
4987
+ }
4988
+
4989
+ for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
4990
+ if (depth === 8) {
4991
+ rawPos = mapImage8Bit(
4992
+ images[imageIndex],
4993
+ pxData,
4994
+ getPxPos,
4995
+ bpp,
4996
+ data,
4997
+ rawPos
4998
+ );
5128
4999
  } else {
5129
- encoding = length;
5130
- length = undefined;
5000
+ mapImageCustomBit(
5001
+ images[imageIndex],
5002
+ pxData,
5003
+ getPxPos,
5004
+ bpp,
5005
+ bits,
5006
+ maxBit
5007
+ );
5008
+ }
5009
+ }
5010
+ if (depth === 8) {
5011
+ if (rawPos !== data.length) {
5012
+ throw new Error("extra data found");
5131
5013
  }
5132
- // legacy write(string, encoding, offset, length) - remove in v0.13
5133
5014
  } else {
5134
- throw new Error(
5135
- 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
5136
- )
5015
+ bits.end();
5137
5016
  }
5138
5017
 
5139
- var remaining = this.length - offset;
5140
- if (length === undefined || length > remaining) length = remaining;
5018
+ return pxData;
5019
+ };
5020
+
5021
+ function dePalette(indata, outdata, width, height, palette) {
5022
+ let pxPos = 0;
5023
+ // use values from palette
5024
+ for (let y = 0; y < height; y++) {
5025
+ for (let x = 0; x < width; x++) {
5026
+ let color = palette[indata[pxPos]];
5027
+
5028
+ if (!color) {
5029
+ throw new Error("index " + indata[pxPos] + " not in palette");
5030
+ }
5141
5031
 
5142
- if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
5143
- throw new RangeError('Attempt to write outside buffer bounds')
5032
+ for (let i = 0; i < 4; i++) {
5033
+ outdata[pxPos + i] = color[i];
5034
+ }
5035
+ pxPos += 4;
5036
+ }
5144
5037
  }
5038
+ }
5145
5039
 
5146
- if (!encoding) encoding = 'utf8';
5040
+ function replaceTransparentColor(indata, outdata, width, height, transColor) {
5041
+ let pxPos = 0;
5042
+ for (let y = 0; y < height; y++) {
5043
+ for (let x = 0; x < width; x++) {
5044
+ let makeTrans = false;
5147
5045
 
5148
- var loweredCase = false;
5149
- for (;;) {
5150
- switch (encoding) {
5151
- case 'hex':
5152
- return hexWrite(this, string, offset, length)
5046
+ if (transColor.length === 1) {
5047
+ if (transColor[0] === indata[pxPos]) {
5048
+ makeTrans = true;
5049
+ }
5050
+ } else if (
5051
+ transColor[0] === indata[pxPos] &&
5052
+ transColor[1] === indata[pxPos + 1] &&
5053
+ transColor[2] === indata[pxPos + 2]
5054
+ ) {
5055
+ makeTrans = true;
5056
+ }
5057
+ if (makeTrans) {
5058
+ for (let i = 0; i < 4; i++) {
5059
+ outdata[pxPos + i] = 0;
5060
+ }
5061
+ }
5062
+ pxPos += 4;
5063
+ }
5064
+ }
5065
+ }
5153
5066
 
5154
- case 'utf8':
5155
- case 'utf-8':
5156
- return utf8Write(this, string, offset, length)
5067
+ function scaleDepth(indata, outdata, width, height, depth) {
5068
+ let maxOutSample = 255;
5069
+ let maxInSample = Math.pow(2, depth) - 1;
5070
+ let pxPos = 0;
5157
5071
 
5158
- case 'ascii':
5159
- return asciiWrite(this, string, offset, length)
5072
+ for (let y = 0; y < height; y++) {
5073
+ for (let x = 0; x < width; x++) {
5074
+ for (let i = 0; i < 4; i++) {
5075
+ outdata[pxPos + i] = Math.floor(
5076
+ (indata[pxPos + i] * maxOutSample) / maxInSample + 0.5
5077
+ );
5078
+ }
5079
+ pxPos += 4;
5080
+ }
5081
+ }
5082
+ }
5160
5083
 
5161
- case 'latin1':
5162
- case 'binary':
5163
- return latin1Write(this, string, offset, length)
5084
+ var formatNormaliser$2 = function (indata, imageData) {
5085
+ let depth = imageData.depth;
5086
+ let width = imageData.width;
5087
+ let height = imageData.height;
5088
+ let colorType = imageData.colorType;
5089
+ let transColor = imageData.transColor;
5090
+ let palette = imageData.palette;
5164
5091
 
5165
- case 'base64':
5166
- // Warning: maxLength not taken into account in base64Write
5167
- return base64Write(this, string, offset, length)
5092
+ let outdata = indata; // only different for 16 bits
5168
5093
 
5169
- case 'ucs2':
5170
- case 'ucs-2':
5171
- case 'utf16le':
5172
- case 'utf-16le':
5173
- return ucs2Write(this, string, offset, length)
5094
+ if (colorType === 3) {
5095
+ // paletted
5096
+ dePalette(indata, outdata, width, height, palette);
5097
+ } else {
5098
+ if (transColor) {
5099
+ replaceTransparentColor(indata, outdata, width, height, transColor);
5100
+ }
5101
+ // if it needs scaling
5102
+ if (depth !== 8) {
5103
+ // if we need to change the buffer size
5104
+ if (depth === 16) {
5105
+ outdata = Buffer.alloc(width * height * 4);
5106
+ }
5107
+ scaleDepth(indata, outdata, width, height, depth);
5108
+ }
5109
+ }
5110
+ return outdata;
5111
+ };
5112
+
5113
+ let util$2 = require$$0__default["default"];
5114
+ let zlib$3 = require$$1__default$1["default"];
5115
+ let ChunkStream = chunkstream.exports;
5116
+ let FilterAsync = filterParseAsync.exports;
5117
+ let Parser$2 = parser.exports;
5118
+ let bitmapper$1 = bitmapper$2;
5119
+ let formatNormaliser$1 = formatNormaliser$2;
5120
+
5121
+ let ParserAsync = (parserAsync.exports = function (options) {
5122
+ ChunkStream.call(this);
5123
+
5124
+ this._parser = new Parser$2(options, {
5125
+ read: this.read.bind(this),
5126
+ error: this._handleError.bind(this),
5127
+ metadata: this._handleMetaData.bind(this),
5128
+ gamma: this.emit.bind(this, "gamma"),
5129
+ palette: this._handlePalette.bind(this),
5130
+ transColor: this._handleTransColor.bind(this),
5131
+ finished: this._finished.bind(this),
5132
+ inflateData: this._inflateData.bind(this),
5133
+ simpleTransparency: this._simpleTransparency.bind(this),
5134
+ headersFinished: this._headersFinished.bind(this),
5135
+ });
5136
+ this._options = options;
5137
+ this.writable = true;
5174
5138
 
5175
- default:
5176
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
5177
- encoding = ('' + encoding).toLowerCase();
5178
- loweredCase = true;
5179
- }
5139
+ this._parser.start();
5140
+ });
5141
+ util$2.inherits(ParserAsync, ChunkStream);
5142
+
5143
+ ParserAsync.prototype._handleError = function (err) {
5144
+ this.emit("error", err);
5145
+
5146
+ this.writable = false;
5147
+
5148
+ this.destroy();
5149
+
5150
+ if (this._inflate && this._inflate.destroy) {
5151
+ this._inflate.destroy();
5152
+ }
5153
+
5154
+ if (this._filter) {
5155
+ this._filter.destroy();
5156
+ // For backward compatibility with Node 7 and below.
5157
+ // Suppress errors due to _inflate calling write() even after
5158
+ // it's destroy()'ed.
5159
+ this._filter.on("error", function () {});
5180
5160
  }
5161
+
5162
+ this.errord = true;
5181
5163
  };
5182
5164
 
5183
- Buffer.prototype.toJSON = function toJSON () {
5184
- return {
5185
- type: 'Buffer',
5186
- data: Array.prototype.slice.call(this._arr || this, 0)
5165
+ ParserAsync.prototype._inflateData = function (data) {
5166
+ if (!this._inflate) {
5167
+ if (this._bitmapInfo.interlace) {
5168
+ this._inflate = zlib$3.createInflate();
5169
+
5170
+ this._inflate.on("error", this.emit.bind(this, "error"));
5171
+ this._filter.on("complete", this._complete.bind(this));
5172
+
5173
+ this._inflate.pipe(this._filter);
5174
+ } else {
5175
+ let rowSize =
5176
+ ((this._bitmapInfo.width *
5177
+ this._bitmapInfo.bpp *
5178
+ this._bitmapInfo.depth +
5179
+ 7) >>
5180
+ 3) +
5181
+ 1;
5182
+ let imageSize = rowSize * this._bitmapInfo.height;
5183
+ let chunkSize = Math.max(imageSize, zlib$3.Z_MIN_CHUNK);
5184
+
5185
+ this._inflate = zlib$3.createInflate({ chunkSize: chunkSize });
5186
+ let leftToInflate = imageSize;
5187
+
5188
+ let emitError = this.emit.bind(this, "error");
5189
+ this._inflate.on("error", function (err) {
5190
+ if (!leftToInflate) {
5191
+ return;
5192
+ }
5193
+
5194
+ emitError(err);
5195
+ });
5196
+ this._filter.on("complete", this._complete.bind(this));
5197
+
5198
+ let filterWrite = this._filter.write.bind(this._filter);
5199
+ this._inflate.on("data", function (chunk) {
5200
+ if (!leftToInflate) {
5201
+ return;
5202
+ }
5203
+
5204
+ if (chunk.length > leftToInflate) {
5205
+ chunk = chunk.slice(0, leftToInflate);
5206
+ }
5207
+
5208
+ leftToInflate -= chunk.length;
5209
+
5210
+ filterWrite(chunk);
5211
+ });
5212
+
5213
+ this._inflate.on("end", this._filter.end.bind(this._filter));
5214
+ }
5187
5215
  }
5216
+ this._inflate.write(data);
5217
+ };
5218
+
5219
+ ParserAsync.prototype._handleMetaData = function (metaData) {
5220
+ this._metaData = metaData;
5221
+ this._bitmapInfo = Object.create(metaData);
5222
+
5223
+ this._filter = new FilterAsync(this._bitmapInfo);
5224
+ };
5225
+
5226
+ ParserAsync.prototype._handleTransColor = function (transColor) {
5227
+ this._bitmapInfo.transColor = transColor;
5228
+ };
5229
+
5230
+ ParserAsync.prototype._handlePalette = function (palette) {
5231
+ this._bitmapInfo.palette = palette;
5232
+ };
5233
+
5234
+ ParserAsync.prototype._simpleTransparency = function () {
5235
+ this._metaData.alpha = true;
5236
+ };
5237
+
5238
+ ParserAsync.prototype._headersFinished = function () {
5239
+ // Up until this point, we don't know if we have a tRNS chunk (alpha)
5240
+ // so we can't emit metadata any earlier
5241
+ this.emit("metadata", this._metaData);
5188
5242
  };
5189
5243
 
5190
- function base64Slice (buf, start, end) {
5191
- if (start === 0 && end === buf.length) {
5192
- return fromByteArray(buf)
5244
+ ParserAsync.prototype._finished = function () {
5245
+ if (this.errord) {
5246
+ return;
5247
+ }
5248
+
5249
+ if (!this._inflate) {
5250
+ this.emit("error", "No Inflate block");
5193
5251
  } else {
5194
- return fromByteArray(buf.slice(start, end))
5252
+ // no more data to inflate
5253
+ this._inflate.end();
5195
5254
  }
5196
- }
5255
+ };
5197
5256
 
5198
- function utf8Slice (buf, start, end) {
5199
- end = Math.min(buf.length, end);
5200
- var res = [];
5257
+ ParserAsync.prototype._complete = function (filteredData) {
5258
+ if (this.errord) {
5259
+ return;
5260
+ }
5201
5261
 
5202
- var i = start;
5203
- while (i < end) {
5204
- var firstByte = buf[i];
5205
- var codePoint = null;
5206
- var bytesPerSequence = (firstByte > 0xEF) ? 4
5207
- : (firstByte > 0xDF) ? 3
5208
- : (firstByte > 0xBF) ? 2
5209
- : 1;
5262
+ let normalisedBitmapData;
5210
5263
 
5211
- if (i + bytesPerSequence <= end) {
5212
- var secondByte, thirdByte, fourthByte, tempCodePoint;
5264
+ try {
5265
+ let bitmapData = bitmapper$1.dataToBitMap(filteredData, this._bitmapInfo);
5213
5266
 
5214
- switch (bytesPerSequence) {
5215
- case 1:
5216
- if (firstByte < 0x80) {
5217
- codePoint = firstByte;
5218
- }
5219
- break
5220
- case 2:
5221
- secondByte = buf[i + 1];
5222
- if ((secondByte & 0xC0) === 0x80) {
5223
- tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
5224
- if (tempCodePoint > 0x7F) {
5225
- codePoint = tempCodePoint;
5267
+ normalisedBitmapData = formatNormaliser$1(bitmapData, this._bitmapInfo);
5268
+ bitmapData = null;
5269
+ } catch (ex) {
5270
+ this._handleError(ex);
5271
+ return;
5272
+ }
5273
+
5274
+ this.emit("parsed", normalisedBitmapData);
5275
+ };
5276
+
5277
+ var packerAsync = {exports: {}};
5278
+
5279
+ var packer = {exports: {}};
5280
+
5281
+ let constants$3 = constants$5;
5282
+
5283
+ var bitpacker = function (dataIn, width, height, options) {
5284
+ let outHasAlpha =
5285
+ [constants$3.COLORTYPE_COLOR_ALPHA, constants$3.COLORTYPE_ALPHA].indexOf(
5286
+ options.colorType
5287
+ ) !== -1;
5288
+ if (options.colorType === options.inputColorType) {
5289
+ let bigEndian = (function () {
5290
+ let buffer = new ArrayBuffer(2);
5291
+ new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
5292
+ // Int16Array uses the platform's endianness.
5293
+ return new Int16Array(buffer)[0] !== 256;
5294
+ })();
5295
+ // If no need to convert to grayscale and alpha is present/absent in both, take a fast route
5296
+ if (options.bitDepth === 8 || (options.bitDepth === 16 && bigEndian)) {
5297
+ return dataIn;
5298
+ }
5299
+ }
5300
+
5301
+ // map to a UInt16 array if data is 16bit, fix endianness below
5302
+ let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
5303
+
5304
+ let maxValue = 255;
5305
+ let inBpp = constants$3.COLORTYPE_TO_BPP_MAP[options.inputColorType];
5306
+ if (inBpp === 4 && !options.inputHasAlpha) {
5307
+ inBpp = 3;
5308
+ }
5309
+ let outBpp = constants$3.COLORTYPE_TO_BPP_MAP[options.colorType];
5310
+ if (options.bitDepth === 16) {
5311
+ maxValue = 65535;
5312
+ outBpp *= 2;
5313
+ }
5314
+ let outData = Buffer.alloc(width * height * outBpp);
5315
+
5316
+ let inIndex = 0;
5317
+ let outIndex = 0;
5318
+
5319
+ let bgColor = options.bgColor || {};
5320
+ if (bgColor.red === undefined) {
5321
+ bgColor.red = maxValue;
5322
+ }
5323
+ if (bgColor.green === undefined) {
5324
+ bgColor.green = maxValue;
5325
+ }
5326
+ if (bgColor.blue === undefined) {
5327
+ bgColor.blue = maxValue;
5328
+ }
5329
+
5330
+ function getRGBA() {
5331
+ let red;
5332
+ let green;
5333
+ let blue;
5334
+ let alpha = maxValue;
5335
+ switch (options.inputColorType) {
5336
+ case constants$3.COLORTYPE_COLOR_ALPHA:
5337
+ alpha = data[inIndex + 3];
5338
+ red = data[inIndex];
5339
+ green = data[inIndex + 1];
5340
+ blue = data[inIndex + 2];
5341
+ break;
5342
+ case constants$3.COLORTYPE_COLOR:
5343
+ red = data[inIndex];
5344
+ green = data[inIndex + 1];
5345
+ blue = data[inIndex + 2];
5346
+ break;
5347
+ case constants$3.COLORTYPE_ALPHA:
5348
+ alpha = data[inIndex + 1];
5349
+ red = data[inIndex];
5350
+ green = red;
5351
+ blue = red;
5352
+ break;
5353
+ case constants$3.COLORTYPE_GRAYSCALE:
5354
+ red = data[inIndex];
5355
+ green = red;
5356
+ blue = red;
5357
+ break;
5358
+ default:
5359
+ throw new Error(
5360
+ "input color type:" +
5361
+ options.inputColorType +
5362
+ " is not supported at present"
5363
+ );
5364
+ }
5365
+
5366
+ if (options.inputHasAlpha) {
5367
+ if (!outHasAlpha) {
5368
+ alpha /= maxValue;
5369
+ red = Math.min(
5370
+ Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
5371
+ maxValue
5372
+ );
5373
+ green = Math.min(
5374
+ Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
5375
+ maxValue
5376
+ );
5377
+ blue = Math.min(
5378
+ Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
5379
+ maxValue
5380
+ );
5381
+ }
5382
+ }
5383
+ return { red: red, green: green, blue: blue, alpha: alpha };
5384
+ }
5385
+
5386
+ for (let y = 0; y < height; y++) {
5387
+ for (let x = 0; x < width; x++) {
5388
+ let rgba = getRGBA();
5389
+
5390
+ switch (options.colorType) {
5391
+ case constants$3.COLORTYPE_COLOR_ALPHA:
5392
+ case constants$3.COLORTYPE_COLOR:
5393
+ if (options.bitDepth === 8) {
5394
+ outData[outIndex] = rgba.red;
5395
+ outData[outIndex + 1] = rgba.green;
5396
+ outData[outIndex + 2] = rgba.blue;
5397
+ if (outHasAlpha) {
5398
+ outData[outIndex + 3] = rgba.alpha;
5226
5399
  }
5227
- }
5228
- break
5229
- case 3:
5230
- secondByte = buf[i + 1];
5231
- thirdByte = buf[i + 2];
5232
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
5233
- tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
5234
- if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
5235
- codePoint = tempCodePoint;
5400
+ } else {
5401
+ outData.writeUInt16BE(rgba.red, outIndex);
5402
+ outData.writeUInt16BE(rgba.green, outIndex + 2);
5403
+ outData.writeUInt16BE(rgba.blue, outIndex + 4);
5404
+ if (outHasAlpha) {
5405
+ outData.writeUInt16BE(rgba.alpha, outIndex + 6);
5236
5406
  }
5237
5407
  }
5238
- break
5239
- case 4:
5240
- secondByte = buf[i + 1];
5241
- thirdByte = buf[i + 2];
5242
- fourthByte = buf[i + 3];
5243
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
5244
- tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
5245
- if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
5246
- codePoint = tempCodePoint;
5408
+ break;
5409
+ case constants$3.COLORTYPE_ALPHA:
5410
+ case constants$3.COLORTYPE_GRAYSCALE: {
5411
+ // Convert to grayscale and alpha
5412
+ let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
5413
+ if (options.bitDepth === 8) {
5414
+ outData[outIndex] = grayscale;
5415
+ if (outHasAlpha) {
5416
+ outData[outIndex + 1] = rgba.alpha;
5417
+ }
5418
+ } else {
5419
+ outData.writeUInt16BE(grayscale, outIndex);
5420
+ if (outHasAlpha) {
5421
+ outData.writeUInt16BE(rgba.alpha, outIndex + 2);
5247
5422
  }
5248
5423
  }
5424
+ break;
5425
+ }
5426
+ default:
5427
+ throw new Error("unrecognised color Type " + options.colorType);
5249
5428
  }
5250
- }
5251
5429
 
5252
- if (codePoint === null) {
5253
- // we did not generate a valid codePoint so insert a
5254
- // replacement char (U+FFFD) and advance only 1 byte
5255
- codePoint = 0xFFFD;
5256
- bytesPerSequence = 1;
5257
- } else if (codePoint > 0xFFFF) {
5258
- // encode to utf16 (surrogate pair dance)
5259
- codePoint -= 0x10000;
5260
- res.push(codePoint >>> 10 & 0x3FF | 0xD800);
5261
- codePoint = 0xDC00 | codePoint & 0x3FF;
5430
+ inIndex += inBpp;
5431
+ outIndex += outBpp;
5262
5432
  }
5263
-
5264
- res.push(codePoint);
5265
- i += bytesPerSequence;
5266
5433
  }
5267
5434
 
5268
- return decodeCodePointsArray(res)
5269
- }
5435
+ return outData;
5436
+ };
5270
5437
 
5271
- // Based on http://stackoverflow.com/a/22747272/680742, the browser with
5272
- // the lowest limit is Chrome, with 0x10000 args.
5273
- // We go 1 magnitude less, for safety
5274
- var MAX_ARGUMENTS_LENGTH = 0x1000;
5438
+ let paethPredictor = paethPredictor$2;
5275
5439
 
5276
- function decodeCodePointsArray (codePoints) {
5277
- var len = codePoints.length;
5278
- if (len <= MAX_ARGUMENTS_LENGTH) {
5279
- return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
5440
+ function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
5441
+ for (let x = 0; x < byteWidth; x++) {
5442
+ rawData[rawPos + x] = pxData[pxPos + x];
5280
5443
  }
5444
+ }
5281
5445
 
5282
- // Decode in chunks to avoid "call stack size exceeded".
5283
- var res = '';
5284
- var i = 0;
5285
- while (i < len) {
5286
- res += String.fromCharCode.apply(
5287
- String,
5288
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
5289
- );
5446
+ function filterSumNone(pxData, pxPos, byteWidth) {
5447
+ let sum = 0;
5448
+ let length = pxPos + byteWidth;
5449
+
5450
+ for (let i = pxPos; i < length; i++) {
5451
+ sum += Math.abs(pxData[i]);
5290
5452
  }
5291
- return res
5453
+ return sum;
5292
5454
  }
5293
5455
 
5294
- function asciiSlice (buf, start, end) {
5295
- var ret = '';
5296
- end = Math.min(buf.length, end);
5456
+ function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
5457
+ for (let x = 0; x < byteWidth; x++) {
5458
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
5459
+ let val = pxData[pxPos + x] - left;
5297
5460
 
5298
- for (var i = start; i < end; ++i) {
5299
- ret += String.fromCharCode(buf[i] & 0x7F);
5461
+ rawData[rawPos + x] = val;
5300
5462
  }
5301
- return ret
5302
5463
  }
5303
5464
 
5304
- function latin1Slice (buf, start, end) {
5305
- var ret = '';
5306
- end = Math.min(buf.length, end);
5465
+ function filterSumSub(pxData, pxPos, byteWidth, bpp) {
5466
+ let sum = 0;
5467
+ for (let x = 0; x < byteWidth; x++) {
5468
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
5469
+ let val = pxData[pxPos + x] - left;
5307
5470
 
5308
- for (var i = start; i < end; ++i) {
5309
- ret += String.fromCharCode(buf[i]);
5471
+ sum += Math.abs(val);
5310
5472
  }
5311
- return ret
5473
+
5474
+ return sum;
5312
5475
  }
5313
5476
 
5314
- function hexSlice (buf, start, end) {
5315
- var len = buf.length;
5477
+ function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
5478
+ for (let x = 0; x < byteWidth; x++) {
5479
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
5480
+ let val = pxData[pxPos + x] - up;
5481
+
5482
+ rawData[rawPos + x] = val;
5483
+ }
5484
+ }
5316
5485
 
5317
- if (!start || start < 0) start = 0;
5318
- if (!end || end < 0 || end > len) end = len;
5486
+ function filterSumUp(pxData, pxPos, byteWidth) {
5487
+ let sum = 0;
5488
+ let length = pxPos + byteWidth;
5489
+ for (let x = pxPos; x < length; x++) {
5490
+ let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
5491
+ let val = pxData[x] - up;
5319
5492
 
5320
- var out = '';
5321
- for (var i = start; i < end; ++i) {
5322
- out += toHex(buf[i]);
5493
+ sum += Math.abs(val);
5323
5494
  }
5324
- return out
5495
+
5496
+ return sum;
5325
5497
  }
5326
5498
 
5327
- function utf16leSlice (buf, start, end) {
5328
- var bytes = buf.slice(start, end);
5329
- var res = '';
5330
- for (var i = 0; i < bytes.length; i += 2) {
5331
- res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
5499
+ function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
5500
+ for (let x = 0; x < byteWidth; x++) {
5501
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
5502
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
5503
+ let val = pxData[pxPos + x] - ((left + up) >> 1);
5504
+
5505
+ rawData[rawPos + x] = val;
5332
5506
  }
5333
- return res
5334
5507
  }
5335
5508
 
5336
- Buffer.prototype.slice = function slice (start, end) {
5337
- var len = this.length;
5338
- start = ~~start;
5339
- end = end === undefined ? len : ~~end;
5509
+ function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
5510
+ let sum = 0;
5511
+ for (let x = 0; x < byteWidth; x++) {
5512
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
5513
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
5514
+ let val = pxData[pxPos + x] - ((left + up) >> 1);
5340
5515
 
5341
- if (start < 0) {
5342
- start += len;
5343
- if (start < 0) start = 0;
5344
- } else if (start > len) {
5345
- start = len;
5516
+ sum += Math.abs(val);
5346
5517
  }
5347
5518
 
5348
- if (end < 0) {
5349
- end += len;
5350
- if (end < 0) end = 0;
5351
- } else if (end > len) {
5352
- end = len;
5519
+ return sum;
5520
+ }
5521
+
5522
+ function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
5523
+ for (let x = 0; x < byteWidth; x++) {
5524
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
5525
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
5526
+ let upleft =
5527
+ pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
5528
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
5529
+
5530
+ rawData[rawPos + x] = val;
5353
5531
  }
5532
+ }
5354
5533
 
5355
- if (end < start) end = start;
5534
+ function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
5535
+ let sum = 0;
5536
+ for (let x = 0; x < byteWidth; x++) {
5537
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
5538
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
5539
+ let upleft =
5540
+ pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
5541
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
5356
5542
 
5357
- var newBuf;
5358
- if (Buffer.TYPED_ARRAY_SUPPORT) {
5359
- newBuf = this.subarray(start, end);
5360
- newBuf.__proto__ = Buffer.prototype;
5361
- } else {
5362
- var sliceLen = end - start;
5363
- newBuf = new Buffer(sliceLen, undefined);
5364
- for (var i = 0; i < sliceLen; ++i) {
5365
- newBuf[i] = this[i + start];
5366
- }
5543
+ sum += Math.abs(val);
5367
5544
  }
5368
5545
 
5369
- return newBuf
5546
+ return sum;
5547
+ }
5548
+
5549
+ let filters = {
5550
+ 0: filterNone,
5551
+ 1: filterSub,
5552
+ 2: filterUp,
5553
+ 3: filterAvg,
5554
+ 4: filterPaeth,
5370
5555
  };
5371
5556
 
5372
- /*
5373
- * Need to make sure that buffer isn't trying to write out of bounds.
5374
- */
5375
- function checkOffset (offset, ext, length) {
5376
- if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
5377
- if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
5378
- }
5557
+ let filterSums = {
5558
+ 0: filterSumNone,
5559
+ 1: filterSumSub,
5560
+ 2: filterSumUp,
5561
+ 3: filterSumAvg,
5562
+ 4: filterSumPaeth,
5563
+ };
5379
5564
 
5380
- Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
5381
- offset = offset | 0;
5382
- byteLength = byteLength | 0;
5383
- if (!noAssert) checkOffset(offset, byteLength, this.length);
5565
+ var filterPack = function (pxData, width, height, options, bpp) {
5566
+ let filterTypes;
5567
+ if (!("filterType" in options) || options.filterType === -1) {
5568
+ filterTypes = [0, 1, 2, 3, 4];
5569
+ } else if (typeof options.filterType === "number") {
5570
+ filterTypes = [options.filterType];
5571
+ } else {
5572
+ throw new Error("unrecognised filter types");
5573
+ }
5384
5574
 
5385
- var val = this[offset];
5386
- var mul = 1;
5387
- var i = 0;
5388
- while (++i < byteLength && (mul *= 0x100)) {
5389
- val += this[offset + i] * mul;
5575
+ if (options.bitDepth === 16) {
5576
+ bpp *= 2;
5390
5577
  }
5578
+ let byteWidth = width * bpp;
5579
+ let rawPos = 0;
5580
+ let pxPos = 0;
5581
+ let rawData = Buffer.alloc((byteWidth + 1) * height);
5391
5582
 
5392
- return val
5393
- };
5583
+ let sel = filterTypes[0];
5394
5584
 
5395
- Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
5396
- offset = offset | 0;
5397
- byteLength = byteLength | 0;
5398
- if (!noAssert) {
5399
- checkOffset(offset, byteLength, this.length);
5400
- }
5585
+ for (let y = 0; y < height; y++) {
5586
+ if (filterTypes.length > 1) {
5587
+ // find best filter for this line (with lowest sum of values)
5588
+ let min = Infinity;
5589
+
5590
+ for (let i = 0; i < filterTypes.length; i++) {
5591
+ let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
5592
+ if (sum < min) {
5593
+ sel = filterTypes[i];
5594
+ min = sum;
5595
+ }
5596
+ }
5597
+ }
5401
5598
 
5402
- var val = this[offset + --byteLength];
5403
- var mul = 1;
5404
- while (byteLength > 0 && (mul *= 0x100)) {
5405
- val += this[offset + --byteLength] * mul;
5599
+ rawData[rawPos] = sel;
5600
+ rawPos++;
5601
+ filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
5602
+ rawPos += byteWidth;
5603
+ pxPos += byteWidth;
5604
+ }
5605
+ return rawData;
5606
+ };
5607
+
5608
+ let constants$2 = constants$5;
5609
+ let CrcStream = crc.exports;
5610
+ let bitPacker = bitpacker;
5611
+ let filter = filterPack;
5612
+ let zlib$2 = require$$1__default$1["default"];
5613
+
5614
+ let Packer$3 = (packer.exports = function (options) {
5615
+ this._options = options;
5616
+
5617
+ options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
5618
+ options.deflateLevel =
5619
+ options.deflateLevel != null ? options.deflateLevel : 9;
5620
+ options.deflateStrategy =
5621
+ options.deflateStrategy != null ? options.deflateStrategy : 3;
5622
+ options.inputHasAlpha =
5623
+ options.inputHasAlpha != null ? options.inputHasAlpha : true;
5624
+ options.deflateFactory = options.deflateFactory || zlib$2.createDeflate;
5625
+ options.bitDepth = options.bitDepth || 8;
5626
+ // This is outputColorType
5627
+ options.colorType =
5628
+ typeof options.colorType === "number"
5629
+ ? options.colorType
5630
+ : constants$2.COLORTYPE_COLOR_ALPHA;
5631
+ options.inputColorType =
5632
+ typeof options.inputColorType === "number"
5633
+ ? options.inputColorType
5634
+ : constants$2.COLORTYPE_COLOR_ALPHA;
5635
+
5636
+ if (
5637
+ [
5638
+ constants$2.COLORTYPE_GRAYSCALE,
5639
+ constants$2.COLORTYPE_COLOR,
5640
+ constants$2.COLORTYPE_COLOR_ALPHA,
5641
+ constants$2.COLORTYPE_ALPHA,
5642
+ ].indexOf(options.colorType) === -1
5643
+ ) {
5644
+ throw new Error(
5645
+ "option color type:" + options.colorType + " is not supported at present"
5646
+ );
5647
+ }
5648
+ if (
5649
+ [
5650
+ constants$2.COLORTYPE_GRAYSCALE,
5651
+ constants$2.COLORTYPE_COLOR,
5652
+ constants$2.COLORTYPE_COLOR_ALPHA,
5653
+ constants$2.COLORTYPE_ALPHA,
5654
+ ].indexOf(options.inputColorType) === -1
5655
+ ) {
5656
+ throw new Error(
5657
+ "option input color type:" +
5658
+ options.inputColorType +
5659
+ " is not supported at present"
5660
+ );
5406
5661
  }
5662
+ if (options.bitDepth !== 8 && options.bitDepth !== 16) {
5663
+ throw new Error(
5664
+ "option bit depth:" + options.bitDepth + " is not supported at present"
5665
+ );
5666
+ }
5667
+ });
5407
5668
 
5408
- return val
5669
+ Packer$3.prototype.getDeflateOptions = function () {
5670
+ return {
5671
+ chunkSize: this._options.deflateChunkSize,
5672
+ level: this._options.deflateLevel,
5673
+ strategy: this._options.deflateStrategy,
5674
+ };
5409
5675
  };
5410
5676
 
5411
- Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
5412
- if (!noAssert) checkOffset(offset, 1, this.length);
5413
- return this[offset]
5677
+ Packer$3.prototype.createDeflate = function () {
5678
+ return this._options.deflateFactory(this.getDeflateOptions());
5414
5679
  };
5415
5680
 
5416
- Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
5417
- if (!noAssert) checkOffset(offset, 2, this.length);
5418
- return this[offset] | (this[offset + 1] << 8)
5681
+ Packer$3.prototype.filterData = function (data, width, height) {
5682
+ // convert to correct format for filtering (e.g. right bpp and bit depth)
5683
+ let packedData = bitPacker(data, width, height, this._options);
5684
+
5685
+ // filter pixel data
5686
+ let bpp = constants$2.COLORTYPE_TO_BPP_MAP[this._options.colorType];
5687
+ let filteredData = filter(packedData, width, height, this._options, bpp);
5688
+ return filteredData;
5419
5689
  };
5420
5690
 
5421
- Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
5422
- if (!noAssert) checkOffset(offset, 2, this.length);
5423
- return (this[offset] << 8) | this[offset + 1]
5691
+ Packer$3.prototype._packChunk = function (type, data) {
5692
+ let len = data ? data.length : 0;
5693
+ let buf = Buffer.alloc(len + 12);
5694
+
5695
+ buf.writeUInt32BE(len, 0);
5696
+ buf.writeUInt32BE(type, 4);
5697
+
5698
+ if (data) {
5699
+ data.copy(buf, 8);
5700
+ }
5701
+
5702
+ buf.writeInt32BE(
5703
+ CrcStream.crc32(buf.slice(4, buf.length - 4)),
5704
+ buf.length - 4
5705
+ );
5706
+ return buf;
5424
5707
  };
5425
5708
 
5426
- Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
5427
- if (!noAssert) checkOffset(offset, 4, this.length);
5709
+ Packer$3.prototype.packGAMA = function (gamma) {
5710
+ let buf = Buffer.alloc(4);
5711
+ buf.writeUInt32BE(Math.floor(gamma * constants$2.GAMMA_DIVISION), 0);
5712
+ return this._packChunk(constants$2.TYPE_gAMA, buf);
5713
+ };
5428
5714
 
5429
- return ((this[offset]) |
5430
- (this[offset + 1] << 8) |
5431
- (this[offset + 2] << 16)) +
5432
- (this[offset + 3] * 0x1000000)
5715
+ Packer$3.prototype.packIHDR = function (width, height) {
5716
+ let buf = Buffer.alloc(13);
5717
+ buf.writeUInt32BE(width, 0);
5718
+ buf.writeUInt32BE(height, 4);
5719
+ buf[8] = this._options.bitDepth; // Bit depth
5720
+ buf[9] = this._options.colorType; // colorType
5721
+ buf[10] = 0; // compression
5722
+ buf[11] = 0; // filter
5723
+ buf[12] = 0; // interlace
5724
+
5725
+ return this._packChunk(constants$2.TYPE_IHDR, buf);
5433
5726
  };
5434
5727
 
5435
- Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
5436
- if (!noAssert) checkOffset(offset, 4, this.length);
5728
+ Packer$3.prototype.packIDAT = function (data) {
5729
+ return this._packChunk(constants$2.TYPE_IDAT, data);
5730
+ };
5437
5731
 
5438
- return (this[offset] * 0x1000000) +
5439
- ((this[offset + 1] << 16) |
5440
- (this[offset + 2] << 8) |
5441
- this[offset + 3])
5732
+ Packer$3.prototype.packIEND = function () {
5733
+ return this._packChunk(constants$2.TYPE_IEND, null);
5442
5734
  };
5443
5735
 
5444
- Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
5445
- offset = offset | 0;
5446
- byteLength = byteLength | 0;
5447
- if (!noAssert) checkOffset(offset, byteLength, this.length);
5736
+ let util$1 = require$$0__default["default"];
5737
+ let Stream$1 = require$$1__default["default"];
5738
+ let constants$1 = constants$5;
5739
+ let Packer$2 = packer.exports;
5448
5740
 
5449
- var val = this[offset];
5450
- var mul = 1;
5451
- var i = 0;
5452
- while (++i < byteLength && (mul *= 0x100)) {
5453
- val += this[offset + i] * mul;
5454
- }
5455
- mul *= 0x80;
5741
+ let PackerAsync = (packerAsync.exports = function (opt) {
5742
+ Stream$1.call(this);
5456
5743
 
5457
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
5744
+ let options = opt || {};
5458
5745
 
5459
- return val
5460
- };
5746
+ this._packer = new Packer$2(options);
5747
+ this._deflate = this._packer.createDeflate();
5748
+
5749
+ this.readable = true;
5750
+ });
5751
+ util$1.inherits(PackerAsync, Stream$1);
5461
5752
 
5462
- Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
5463
- offset = offset | 0;
5464
- byteLength = byteLength | 0;
5465
- if (!noAssert) checkOffset(offset, byteLength, this.length);
5753
+ PackerAsync.prototype.pack = function (data, width, height, gamma) {
5754
+ // Signature
5755
+ this.emit("data", Buffer.from(constants$1.PNG_SIGNATURE));
5756
+ this.emit("data", this._packer.packIHDR(width, height));
5466
5757
 
5467
- var i = byteLength;
5468
- var mul = 1;
5469
- var val = this[offset + --i];
5470
- while (i > 0 && (mul *= 0x100)) {
5471
- val += this[offset + --i] * mul;
5758
+ if (gamma) {
5759
+ this.emit("data", this._packer.packGAMA(gamma));
5472
5760
  }
5473
- mul *= 0x80;
5474
5761
 
5475
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
5762
+ let filteredData = this._packer.filterData(data, width, height);
5476
5763
 
5477
- return val
5478
- };
5764
+ // compress it
5765
+ this._deflate.on("error", this.emit.bind(this, "error"));
5479
5766
 
5480
- Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
5481
- if (!noAssert) checkOffset(offset, 1, this.length);
5482
- if (!(this[offset] & 0x80)) return (this[offset])
5483
- return ((0xff - this[offset] + 1) * -1)
5484
- };
5767
+ this._deflate.on(
5768
+ "data",
5769
+ function (compressedData) {
5770
+ this.emit("data", this._packer.packIDAT(compressedData));
5771
+ }.bind(this)
5772
+ );
5485
5773
 
5486
- Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
5487
- if (!noAssert) checkOffset(offset, 2, this.length);
5488
- var val = this[offset] | (this[offset + 1] << 8);
5489
- return (val & 0x8000) ? val | 0xFFFF0000 : val
5490
- };
5774
+ this._deflate.on(
5775
+ "end",
5776
+ function () {
5777
+ this.emit("data", this._packer.packIEND());
5778
+ this.emit("end");
5779
+ }.bind(this)
5780
+ );
5491
5781
 
5492
- Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
5493
- if (!noAssert) checkOffset(offset, 2, this.length);
5494
- var val = this[offset + 1] | (this[offset] << 8);
5495
- return (val & 0x8000) ? val | 0xFFFF0000 : val
5782
+ this._deflate.end(filteredData);
5496
5783
  };
5497
5784
 
5498
- Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
5499
- if (!noAssert) checkOffset(offset, 4, this.length);
5785
+ var pngSync = {};
5500
5786
 
5501
- return (this[offset]) |
5502
- (this[offset + 1] << 8) |
5503
- (this[offset + 2] << 16) |
5504
- (this[offset + 3] << 24)
5505
- };
5787
+ var syncInflate = {exports: {}};
5506
5788
 
5507
- Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
5508
- if (!noAssert) checkOffset(offset, 4, this.length);
5789
+ (function (module, exports) {
5509
5790
 
5510
- return (this[offset] << 24) |
5511
- (this[offset + 1] << 16) |
5512
- (this[offset + 2] << 8) |
5513
- (this[offset + 3])
5514
- };
5791
+ let assert = require$$0__default$1["default"].ok;
5792
+ let zlib = require$$1__default$1["default"];
5793
+ let util = require$$0__default["default"];
5515
5794
 
5516
- Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
5517
- if (!noAssert) checkOffset(offset, 4, this.length);
5518
- return read(this, offset, true, 23, 4)
5519
- };
5795
+ let kMaxLength = require$$3__default["default"].kMaxLength;
5520
5796
 
5521
- Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
5522
- if (!noAssert) checkOffset(offset, 4, this.length);
5523
- return read(this, offset, false, 23, 4)
5524
- };
5797
+ function Inflate(opts) {
5798
+ if (!(this instanceof Inflate)) {
5799
+ return new Inflate(opts);
5800
+ }
5525
5801
 
5526
- Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
5527
- if (!noAssert) checkOffset(offset, 8, this.length);
5528
- return read(this, offset, true, 52, 8)
5529
- };
5802
+ if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
5803
+ opts.chunkSize = zlib.Z_MIN_CHUNK;
5804
+ }
5530
5805
 
5531
- Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
5532
- if (!noAssert) checkOffset(offset, 8, this.length);
5533
- return read(this, offset, false, 52, 8)
5534
- };
5806
+ zlib.Inflate.call(this, opts);
5535
5807
 
5536
- function checkInt (buf, value, offset, ext, max, min) {
5537
- if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
5538
- if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
5539
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
5540
- }
5808
+ // Node 8 --> 9 compatibility check
5809
+ this._offset = this._offset === undefined ? this._outOffset : this._offset;
5810
+ this._buffer = this._buffer || this._outBuffer;
5541
5811
 
5542
- Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
5543
- value = +value;
5544
- offset = offset | 0;
5545
- byteLength = byteLength | 0;
5546
- if (!noAssert) {
5547
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
5548
- checkInt(this, value, offset, byteLength, maxBytes, 0);
5549
- }
5812
+ if (opts && opts.maxLength != null) {
5813
+ this._maxLength = opts.maxLength;
5814
+ }
5815
+ }
5550
5816
 
5551
- var mul = 1;
5552
- var i = 0;
5553
- this[offset] = value & 0xFF;
5554
- while (++i < byteLength && (mul *= 0x100)) {
5555
- this[offset + i] = (value / mul) & 0xFF;
5556
- }
5817
+ function createInflate(opts) {
5818
+ return new Inflate(opts);
5819
+ }
5557
5820
 
5558
- return offset + byteLength
5559
- };
5821
+ function _close(engine, callback) {
5822
+ if (callback) {
5823
+ process.nextTick(callback);
5824
+ }
5560
5825
 
5561
- Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
5562
- value = +value;
5563
- offset = offset | 0;
5564
- byteLength = byteLength | 0;
5565
- if (!noAssert) {
5566
- var maxBytes = Math.pow(2, 8 * byteLength) - 1;
5567
- checkInt(this, value, offset, byteLength, maxBytes, 0);
5568
- }
5826
+ // Caller may invoke .close after a zlib error (which will null _handle).
5827
+ if (!engine._handle) {
5828
+ return;
5829
+ }
5569
5830
 
5570
- var i = byteLength - 1;
5571
- var mul = 1;
5572
- this[offset + i] = value & 0xFF;
5573
- while (--i >= 0 && (mul *= 0x100)) {
5574
- this[offset + i] = (value / mul) & 0xFF;
5575
- }
5831
+ engine._handle.close();
5832
+ engine._handle = null;
5833
+ }
5576
5834
 
5577
- return offset + byteLength
5578
- };
5835
+ Inflate.prototype._processChunk = function (chunk, flushFlag, asyncCb) {
5836
+ if (typeof asyncCb === "function") {
5837
+ return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
5838
+ }
5579
5839
 
5580
- Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
5581
- value = +value;
5582
- offset = offset | 0;
5583
- if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
5584
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
5585
- this[offset] = (value & 0xff);
5586
- return offset + 1
5587
- };
5840
+ let self = this;
5588
5841
 
5589
- function objectWriteUInt16 (buf, value, offset, littleEndian) {
5590
- if (value < 0) value = 0xffff + value + 1;
5591
- for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
5592
- buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
5593
- (littleEndian ? i : 1 - i) * 8;
5594
- }
5595
- }
5842
+ let availInBefore = chunk && chunk.length;
5843
+ let availOutBefore = this._chunkSize - this._offset;
5844
+ let leftToInflate = this._maxLength;
5845
+ let inOff = 0;
5596
5846
 
5597
- Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
5598
- value = +value;
5599
- offset = offset | 0;
5600
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
5601
- if (Buffer.TYPED_ARRAY_SUPPORT) {
5602
- this[offset] = (value & 0xff);
5603
- this[offset + 1] = (value >>> 8);
5604
- } else {
5605
- objectWriteUInt16(this, value, offset, true);
5606
- }
5607
- return offset + 2
5608
- };
5847
+ let buffers = [];
5848
+ let nread = 0;
5609
5849
 
5610
- Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
5611
- value = +value;
5612
- offset = offset | 0;
5613
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
5614
- if (Buffer.TYPED_ARRAY_SUPPORT) {
5615
- this[offset] = (value >>> 8);
5616
- this[offset + 1] = (value & 0xff);
5617
- } else {
5618
- objectWriteUInt16(this, value, offset, false);
5619
- }
5620
- return offset + 2
5621
- };
5850
+ let error;
5851
+ this.on("error", function (err) {
5852
+ error = err;
5853
+ });
5622
5854
 
5623
- function objectWriteUInt32 (buf, value, offset, littleEndian) {
5624
- if (value < 0) value = 0xffffffff + value + 1;
5625
- for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
5626
- buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
5627
- }
5628
- }
5855
+ function handleChunk(availInAfter, availOutAfter) {
5856
+ if (self._hadError) {
5857
+ return;
5858
+ }
5629
5859
 
5630
- Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
5631
- value = +value;
5632
- offset = offset | 0;
5633
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
5634
- if (Buffer.TYPED_ARRAY_SUPPORT) {
5635
- this[offset + 3] = (value >>> 24);
5636
- this[offset + 2] = (value >>> 16);
5637
- this[offset + 1] = (value >>> 8);
5638
- this[offset] = (value & 0xff);
5639
- } else {
5640
- objectWriteUInt32(this, value, offset, true);
5641
- }
5642
- return offset + 4
5643
- };
5860
+ let have = availOutBefore - availOutAfter;
5861
+ assert(have >= 0, "have should not go down");
5644
5862
 
5645
- Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
5646
- value = +value;
5647
- offset = offset | 0;
5648
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
5649
- if (Buffer.TYPED_ARRAY_SUPPORT) {
5650
- this[offset] = (value >>> 24);
5651
- this[offset + 1] = (value >>> 16);
5652
- this[offset + 2] = (value >>> 8);
5653
- this[offset + 3] = (value & 0xff);
5654
- } else {
5655
- objectWriteUInt32(this, value, offset, false);
5656
- }
5657
- return offset + 4
5658
- };
5863
+ if (have > 0) {
5864
+ let out = self._buffer.slice(self._offset, self._offset + have);
5865
+ self._offset += have;
5659
5866
 
5660
- Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
5661
- value = +value;
5662
- offset = offset | 0;
5663
- if (!noAssert) {
5664
- var limit = Math.pow(2, 8 * byteLength - 1);
5867
+ if (out.length > leftToInflate) {
5868
+ out = out.slice(0, leftToInflate);
5869
+ }
5665
5870
 
5666
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
5667
- }
5871
+ buffers.push(out);
5872
+ nread += out.length;
5873
+ leftToInflate -= out.length;
5668
5874
 
5669
- var i = 0;
5670
- var mul = 1;
5671
- var sub = 0;
5672
- this[offset] = value & 0xFF;
5673
- while (++i < byteLength && (mul *= 0x100)) {
5674
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
5675
- sub = 1;
5676
- }
5677
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
5678
- }
5875
+ if (leftToInflate === 0) {
5876
+ return false;
5877
+ }
5878
+ }
5679
5879
 
5680
- return offset + byteLength
5681
- };
5880
+ if (availOutAfter === 0 || self._offset >= self._chunkSize) {
5881
+ availOutBefore = self._chunkSize;
5882
+ self._offset = 0;
5883
+ self._buffer = Buffer.allocUnsafe(self._chunkSize);
5884
+ }
5682
5885
 
5683
- Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
5684
- value = +value;
5685
- offset = offset | 0;
5686
- if (!noAssert) {
5687
- var limit = Math.pow(2, 8 * byteLength - 1);
5886
+ if (availOutAfter === 0) {
5887
+ inOff += availInBefore - availInAfter;
5888
+ availInBefore = availInAfter;
5688
5889
 
5689
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
5690
- }
5890
+ return true;
5891
+ }
5691
5892
 
5692
- var i = byteLength - 1;
5693
- var mul = 1;
5694
- var sub = 0;
5695
- this[offset + i] = value & 0xFF;
5696
- while (--i >= 0 && (mul *= 0x100)) {
5697
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
5698
- sub = 1;
5699
- }
5700
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
5701
- }
5893
+ return false;
5894
+ }
5702
5895
 
5703
- return offset + byteLength
5704
- };
5896
+ assert(this._handle, "zlib binding closed");
5897
+ let res;
5898
+ do {
5899
+ res = this._handle.writeSync(
5900
+ flushFlag,
5901
+ chunk, // in
5902
+ inOff, // in_off
5903
+ availInBefore, // in_len
5904
+ this._buffer, // out
5905
+ this._offset, //out_off
5906
+ availOutBefore
5907
+ ); // out_len
5908
+ // Node 8 --> 9 compatibility check
5909
+ res = res || this._writeState;
5910
+ } while (!this._hadError && handleChunk(res[0], res[1]));
5911
+
5912
+ if (this._hadError) {
5913
+ throw error;
5914
+ }
5705
5915
 
5706
- Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
5707
- value = +value;
5708
- offset = offset | 0;
5709
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
5710
- if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
5711
- if (value < 0) value = 0xff + value + 1;
5712
- this[offset] = (value & 0xff);
5713
- return offset + 1
5714
- };
5916
+ if (nread >= kMaxLength) {
5917
+ _close(this);
5918
+ throw new RangeError(
5919
+ "Cannot create final Buffer. It would be larger than 0x" +
5920
+ kMaxLength.toString(16) +
5921
+ " bytes"
5922
+ );
5923
+ }
5715
5924
 
5716
- Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
5717
- value = +value;
5718
- offset = offset | 0;
5719
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
5720
- if (Buffer.TYPED_ARRAY_SUPPORT) {
5721
- this[offset] = (value & 0xff);
5722
- this[offset + 1] = (value >>> 8);
5723
- } else {
5724
- objectWriteUInt16(this, value, offset, true);
5725
- }
5726
- return offset + 2
5727
- };
5925
+ let buf = Buffer.concat(buffers, nread);
5926
+ _close(this);
5728
5927
 
5729
- Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
5730
- value = +value;
5731
- offset = offset | 0;
5732
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
5733
- if (Buffer.TYPED_ARRAY_SUPPORT) {
5734
- this[offset] = (value >>> 8);
5735
- this[offset + 1] = (value & 0xff);
5736
- } else {
5737
- objectWriteUInt16(this, value, offset, false);
5738
- }
5739
- return offset + 2
5740
- };
5928
+ return buf;
5929
+ };
5741
5930
 
5742
- Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
5743
- value = +value;
5744
- offset = offset | 0;
5745
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
5746
- if (Buffer.TYPED_ARRAY_SUPPORT) {
5747
- this[offset] = (value & 0xff);
5748
- this[offset + 1] = (value >>> 8);
5749
- this[offset + 2] = (value >>> 16);
5750
- this[offset + 3] = (value >>> 24);
5751
- } else {
5752
- objectWriteUInt32(this, value, offset, true);
5753
- }
5754
- return offset + 4
5755
- };
5931
+ util.inherits(Inflate, zlib.Inflate);
5756
5932
 
5757
- Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
5758
- value = +value;
5759
- offset = offset | 0;
5760
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
5761
- if (value < 0) value = 0xffffffff + value + 1;
5762
- if (Buffer.TYPED_ARRAY_SUPPORT) {
5763
- this[offset] = (value >>> 24);
5764
- this[offset + 1] = (value >>> 16);
5765
- this[offset + 2] = (value >>> 8);
5766
- this[offset + 3] = (value & 0xff);
5767
- } else {
5768
- objectWriteUInt32(this, value, offset, false);
5769
- }
5770
- return offset + 4
5771
- };
5933
+ function zlibBufferSync(engine, buffer) {
5934
+ if (typeof buffer === "string") {
5935
+ buffer = Buffer.from(buffer);
5936
+ }
5937
+ if (!(buffer instanceof Buffer)) {
5938
+ throw new TypeError("Not a string or buffer");
5939
+ }
5772
5940
 
5773
- function checkIEEE754 (buf, value, offset, ext, max, min) {
5774
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
5775
- if (offset < 0) throw new RangeError('Index out of range')
5776
- }
5941
+ let flushFlag = engine._finishFlushFlag;
5942
+ if (flushFlag == null) {
5943
+ flushFlag = zlib.Z_FINISH;
5944
+ }
5777
5945
 
5778
- function writeFloat (buf, value, offset, littleEndian, noAssert) {
5779
- if (!noAssert) {
5780
- checkIEEE754(buf, value, offset, 4);
5781
- }
5782
- write(buf, value, offset, littleEndian, 23, 4);
5783
- return offset + 4
5784
- }
5946
+ return engine._processChunk(buffer, flushFlag);
5947
+ }
5785
5948
 
5786
- Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
5787
- return writeFloat(this, value, offset, true, noAssert)
5788
- };
5949
+ function inflateSync(buffer, opts) {
5950
+ return zlibBufferSync(new Inflate(opts), buffer);
5951
+ }
5789
5952
 
5790
- Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
5791
- return writeFloat(this, value, offset, false, noAssert)
5953
+ module.exports = exports = inflateSync;
5954
+ exports.Inflate = Inflate;
5955
+ exports.createInflate = createInflate;
5956
+ exports.inflateSync = inflateSync;
5957
+ } (syncInflate, syncInflate.exports));
5958
+
5959
+ var syncReader = {exports: {}};
5960
+
5961
+ let SyncReader$2 = (syncReader.exports = function (buffer) {
5962
+ this._buffer = buffer;
5963
+ this._reads = [];
5964
+ });
5965
+
5966
+ SyncReader$2.prototype.read = function (length, callback) {
5967
+ this._reads.push({
5968
+ length: Math.abs(length), // if length < 0 then at most this length
5969
+ allowLess: length < 0,
5970
+ func: callback,
5971
+ });
5792
5972
  };
5793
5973
 
5794
- function writeDouble (buf, value, offset, littleEndian, noAssert) {
5795
- if (!noAssert) {
5796
- checkIEEE754(buf, value, offset, 8);
5974
+ SyncReader$2.prototype.process = function () {
5975
+ // as long as there is any data and read requests
5976
+ while (this._reads.length > 0 && this._buffer.length) {
5977
+ let read = this._reads[0];
5978
+
5979
+ if (
5980
+ this._buffer.length &&
5981
+ (this._buffer.length >= read.length || read.allowLess)
5982
+ ) {
5983
+ // ok there is any data so that we can satisfy this request
5984
+ this._reads.shift(); // == read
5985
+
5986
+ let buf = this._buffer;
5987
+
5988
+ this._buffer = buf.slice(read.length);
5989
+
5990
+ read.func.call(this, buf.slice(0, read.length));
5991
+ } else {
5992
+ break;
5993
+ }
5994
+ }
5995
+
5996
+ if (this._reads.length > 0) {
5997
+ return new Error("There are some read requests waitng on finished stream");
5797
5998
  }
5798
- write(buf, value, offset, littleEndian, 52, 8);
5799
- return offset + 8
5800
- }
5801
5999
 
5802
- Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
5803
- return writeDouble(this, value, offset, true, noAssert)
6000
+ if (this._buffer.length > 0) {
6001
+ return new Error("unrecognised content at end of stream");
6002
+ }
5804
6003
  };
5805
6004
 
5806
- Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
5807
- return writeDouble(this, value, offset, false, noAssert)
6005
+ var filterParseSync = {};
6006
+
6007
+ let SyncReader$1 = syncReader.exports;
6008
+ let Filter = filterParse.exports;
6009
+
6010
+ filterParseSync.process = function (inBuffer, bitmapInfo) {
6011
+ let outBuffers = [];
6012
+ let reader = new SyncReader$1(inBuffer);
6013
+ let filter = new Filter(bitmapInfo, {
6014
+ read: reader.read.bind(reader),
6015
+ write: function (bufferPart) {
6016
+ outBuffers.push(bufferPart);
6017
+ },
6018
+ complete: function () {},
6019
+ });
6020
+
6021
+ filter.start();
6022
+ reader.process();
6023
+
6024
+ return Buffer.concat(outBuffers);
5808
6025
  };
5809
6026
 
5810
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
5811
- Buffer.prototype.copy = function copy (target, targetStart, start, end) {
5812
- if (!start) start = 0;
5813
- if (!end && end !== 0) end = this.length;
5814
- if (targetStart >= target.length) targetStart = target.length;
5815
- if (!targetStart) targetStart = 0;
5816
- if (end > 0 && end < start) end = start;
6027
+ let hasSyncZlib$1 = true;
6028
+ let zlib$1 = require$$1__default$1["default"];
6029
+ let inflateSync = syncInflate.exports;
6030
+ if (!zlib$1.deflateSync) {
6031
+ hasSyncZlib$1 = false;
6032
+ }
6033
+ let SyncReader = syncReader.exports;
6034
+ let FilterSync = filterParseSync;
6035
+ let Parser$1 = parser.exports;
6036
+ let bitmapper = bitmapper$2;
6037
+ let formatNormaliser = formatNormaliser$2;
5817
6038
 
5818
- // Copy 0 bytes; we're done
5819
- if (end === start) return 0
5820
- if (target.length === 0 || this.length === 0) return 0
6039
+ var parserSync = function (buffer, options) {
6040
+ if (!hasSyncZlib$1) {
6041
+ throw new Error(
6042
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
6043
+ );
6044
+ }
5821
6045
 
5822
- // Fatal error conditions
5823
- if (targetStart < 0) {
5824
- throw new RangeError('targetStart out of bounds')
6046
+ let err;
6047
+ function handleError(_err_) {
6048
+ err = _err_;
5825
6049
  }
5826
- if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
5827
- if (end < 0) throw new RangeError('sourceEnd out of bounds')
5828
6050
 
5829
- // Are we oob?
5830
- if (end > this.length) end = this.length;
5831
- if (target.length - targetStart < end - start) {
5832
- end = target.length - targetStart + start;
6051
+ let metaData;
6052
+ function handleMetaData(_metaData_) {
6053
+ metaData = _metaData_;
5833
6054
  }
5834
6055
 
5835
- var len = end - start;
5836
- var i;
6056
+ function handleTransColor(transColor) {
6057
+ metaData.transColor = transColor;
6058
+ }
5837
6059
 
5838
- if (this === target && start < targetStart && targetStart < end) {
5839
- // descending copy from end
5840
- for (i = len - 1; i >= 0; --i) {
5841
- target[i + targetStart] = this[i + start];
5842
- }
5843
- } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
5844
- // ascending copy from start
5845
- for (i = 0; i < len; ++i) {
5846
- target[i + targetStart] = this[i + start];
5847
- }
5848
- } else {
5849
- Uint8Array.prototype.set.call(
5850
- target,
5851
- this.subarray(start, start + len),
5852
- targetStart
5853
- );
6060
+ function handlePalette(palette) {
6061
+ metaData.palette = palette;
5854
6062
  }
5855
6063
 
5856
- return len
5857
- };
5858
-
5859
- // Usage:
5860
- // buffer.fill(number[, offset[, end]])
5861
- // buffer.fill(buffer[, offset[, end]])
5862
- // buffer.fill(string[, offset[, end]][, encoding])
5863
- Buffer.prototype.fill = function fill (val, start, end, encoding) {
5864
- // Handle string cases:
5865
- if (typeof val === 'string') {
5866
- if (typeof start === 'string') {
5867
- encoding = start;
5868
- start = 0;
5869
- end = this.length;
5870
- } else if (typeof end === 'string') {
5871
- encoding = end;
5872
- end = this.length;
5873
- }
5874
- if (val.length === 1) {
5875
- var code = val.charCodeAt(0);
5876
- if (code < 256) {
5877
- val = code;
5878
- }
5879
- }
5880
- if (encoding !== undefined && typeof encoding !== 'string') {
5881
- throw new TypeError('encoding must be a string')
5882
- }
5883
- if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
5884
- throw new TypeError('Unknown encoding: ' + encoding)
5885
- }
5886
- } else if (typeof val === 'number') {
5887
- val = val & 255;
6064
+ function handleSimpleTransparency() {
6065
+ metaData.alpha = true;
5888
6066
  }
5889
6067
 
5890
- // Invalid ranges are not set to a default, so can range check early.
5891
- if (start < 0 || this.length < start || this.length < end) {
5892
- throw new RangeError('Out of range index')
6068
+ let gamma;
6069
+ function handleGamma(_gamma_) {
6070
+ gamma = _gamma_;
5893
6071
  }
5894
6072
 
5895
- if (end <= start) {
5896
- return this
6073
+ let inflateDataList = [];
6074
+ function handleInflateData(inflatedData) {
6075
+ inflateDataList.push(inflatedData);
5897
6076
  }
5898
6077
 
5899
- start = start >>> 0;
5900
- end = end === undefined ? this.length : end >>> 0;
6078
+ let reader = new SyncReader(buffer);
5901
6079
 
5902
- if (!val) val = 0;
6080
+ let parser = new Parser$1(options, {
6081
+ read: reader.read.bind(reader),
6082
+ error: handleError,
6083
+ metadata: handleMetaData,
6084
+ gamma: handleGamma,
6085
+ palette: handlePalette,
6086
+ transColor: handleTransColor,
6087
+ inflateData: handleInflateData,
6088
+ simpleTransparency: handleSimpleTransparency,
6089
+ });
5903
6090
 
5904
- var i;
5905
- if (typeof val === 'number') {
5906
- for (i = start; i < end; ++i) {
5907
- this[i] = val;
5908
- }
5909
- } else {
5910
- var bytes = internalIsBuffer(val)
5911
- ? val
5912
- : utf8ToBytes(new Buffer(val, encoding).toString());
5913
- var len = bytes.length;
5914
- for (i = 0; i < end - start; ++i) {
5915
- this[i + start] = bytes[i % len];
5916
- }
5917
- }
6091
+ parser.start();
6092
+ reader.process();
5918
6093
 
5919
- return this
5920
- };
6094
+ if (err) {
6095
+ throw err;
6096
+ }
5921
6097
 
5922
- // HELPER FUNCTIONS
5923
- // ================
6098
+ //join together the inflate datas
6099
+ let inflateData = Buffer.concat(inflateDataList);
6100
+ inflateDataList.length = 0;
5924
6101
 
5925
- var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
6102
+ let inflatedData;
6103
+ if (metaData.interlace) {
6104
+ inflatedData = zlib$1.inflateSync(inflateData);
6105
+ } else {
6106
+ let rowSize =
6107
+ ((metaData.width * metaData.bpp * metaData.depth + 7) >> 3) + 1;
6108
+ let imageSize = rowSize * metaData.height;
6109
+ inflatedData = inflateSync(inflateData, {
6110
+ chunkSize: imageSize,
6111
+ maxLength: imageSize,
6112
+ });
6113
+ }
6114
+ inflateData = null;
5926
6115
 
5927
- function base64clean (str) {
5928
- // Node strips out invalid characters like \n and \t from the string, base64-js does not
5929
- str = stringtrim(str).replace(INVALID_BASE64_RE, '');
5930
- // Node converts strings with length < 2 to ''
5931
- if (str.length < 2) return ''
5932
- // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
5933
- while (str.length % 4 !== 0) {
5934
- str = str + '=';
6116
+ if (!inflatedData || !inflatedData.length) {
6117
+ throw new Error("bad png - invalid inflate data response");
5935
6118
  }
5936
- return str
5937
- }
5938
6119
 
5939
- function stringtrim (str) {
5940
- if (str.trim) return str.trim()
5941
- return str.replace(/^\s+|\s+$/g, '')
5942
- }
6120
+ let unfilteredData = FilterSync.process(inflatedData, metaData);
6121
+ inflateData = null;
5943
6122
 
5944
- function toHex (n) {
5945
- if (n < 16) return '0' + n.toString(16)
5946
- return n.toString(16)
5947
- }
6123
+ let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
6124
+ unfilteredData = null;
5948
6125
 
5949
- function utf8ToBytes (string, units) {
5950
- units = units || Infinity;
5951
- var codePoint;
5952
- var length = string.length;
5953
- var leadSurrogate = null;
5954
- var bytes = [];
6126
+ let normalisedBitmapData = formatNormaliser(bitmapData, metaData);
5955
6127
 
5956
- for (var i = 0; i < length; ++i) {
5957
- codePoint = string.charCodeAt(i);
6128
+ metaData.data = normalisedBitmapData;
6129
+ metaData.gamma = gamma || 0;
5958
6130
 
5959
- // is surrogate component
5960
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
5961
- // last char was a lead
5962
- if (!leadSurrogate) {
5963
- // no lead yet
5964
- if (codePoint > 0xDBFF) {
5965
- // unexpected trail
5966
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
5967
- continue
5968
- } else if (i + 1 === length) {
5969
- // unpaired lead
5970
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
5971
- continue
5972
- }
6131
+ return metaData;
6132
+ };
5973
6133
 
5974
- // valid lead
5975
- leadSurrogate = codePoint;
6134
+ let hasSyncZlib = true;
6135
+ let zlib = require$$1__default$1["default"];
6136
+ if (!zlib.deflateSync) {
6137
+ hasSyncZlib = false;
6138
+ }
6139
+ let constants = constants$5;
6140
+ let Packer$1 = packer.exports;
5976
6141
 
5977
- continue
5978
- }
6142
+ var packerSync = function (metaData, opt) {
6143
+ if (!hasSyncZlib) {
6144
+ throw new Error(
6145
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
6146
+ );
6147
+ }
5979
6148
 
5980
- // 2 leads in a row
5981
- if (codePoint < 0xDC00) {
5982
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
5983
- leadSurrogate = codePoint;
5984
- continue
5985
- }
6149
+ let options = opt || {};
5986
6150
 
5987
- // valid surrogate pair
5988
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
5989
- } else if (leadSurrogate) {
5990
- // valid bmp char, but last char was a lead
5991
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
5992
- }
6151
+ let packer = new Packer$1(options);
5993
6152
 
5994
- leadSurrogate = null;
6153
+ let chunks = [];
5995
6154
 
5996
- // encode utf8
5997
- if (codePoint < 0x80) {
5998
- if ((units -= 1) < 0) break
5999
- bytes.push(codePoint);
6000
- } else if (codePoint < 0x800) {
6001
- if ((units -= 2) < 0) break
6002
- bytes.push(
6003
- codePoint >> 0x6 | 0xC0,
6004
- codePoint & 0x3F | 0x80
6005
- );
6006
- } else if (codePoint < 0x10000) {
6007
- if ((units -= 3) < 0) break
6008
- bytes.push(
6009
- codePoint >> 0xC | 0xE0,
6010
- codePoint >> 0x6 & 0x3F | 0x80,
6011
- codePoint & 0x3F | 0x80
6012
- );
6013
- } else if (codePoint < 0x110000) {
6014
- if ((units -= 4) < 0) break
6015
- bytes.push(
6016
- codePoint >> 0x12 | 0xF0,
6017
- codePoint >> 0xC & 0x3F | 0x80,
6018
- codePoint >> 0x6 & 0x3F | 0x80,
6019
- codePoint & 0x3F | 0x80
6020
- );
6021
- } else {
6022
- throw new Error('Invalid code point')
6023
- }
6024
- }
6155
+ // Signature
6156
+ chunks.push(Buffer.from(constants.PNG_SIGNATURE));
6025
6157
 
6026
- return bytes
6027
- }
6158
+ // Header
6159
+ chunks.push(packer.packIHDR(metaData.width, metaData.height));
6028
6160
 
6029
- function asciiToBytes (str) {
6030
- var byteArray = [];
6031
- for (var i = 0; i < str.length; ++i) {
6032
- // Node's code seems to be doing this and not & 0x7F..
6033
- byteArray.push(str.charCodeAt(i) & 0xFF);
6161
+ if (metaData.gamma) {
6162
+ chunks.push(packer.packGAMA(metaData.gamma));
6034
6163
  }
6035
- return byteArray
6036
- }
6037
6164
 
6038
- function utf16leToBytes (str, units) {
6039
- var c, hi, lo;
6040
- var byteArray = [];
6041
- for (var i = 0; i < str.length; ++i) {
6042
- if ((units -= 2) < 0) break
6165
+ let filteredData = packer.filterData(
6166
+ metaData.data,
6167
+ metaData.width,
6168
+ metaData.height
6169
+ );
6043
6170
 
6044
- c = str.charCodeAt(i);
6045
- hi = c >> 8;
6046
- lo = c % 256;
6047
- byteArray.push(lo);
6048
- byteArray.push(hi);
6171
+ // compress it
6172
+ let compressedData = zlib.deflateSync(
6173
+ filteredData,
6174
+ packer.getDeflateOptions()
6175
+ );
6176
+ filteredData = null;
6177
+
6178
+ if (!compressedData || !compressedData.length) {
6179
+ throw new Error("bad png - invalid compressed data response");
6049
6180
  }
6181
+ chunks.push(packer.packIDAT(compressedData));
6050
6182
 
6051
- return byteArray
6052
- }
6183
+ // End
6184
+ chunks.push(packer.packIEND());
6185
+
6186
+ return Buffer.concat(chunks);
6187
+ };
6053
6188
 
6189
+ let parse = parserSync;
6190
+ let pack = packerSync;
6054
6191
 
6055
- function base64ToBytes (str) {
6056
- return toByteArray(base64clean(str))
6057
- }
6192
+ pngSync.read = function (buffer, options) {
6193
+ return parse(buffer, options || {});
6194
+ };
6058
6195
 
6059
- function blitBuffer (src, dst, offset, length) {
6060
- for (var i = 0; i < length; ++i) {
6061
- if ((i + offset >= dst.length) || (i >= src.length)) break
6062
- dst[i + offset] = src[i];
6063
- }
6064
- return i
6065
- }
6196
+ pngSync.write = function (png, options) {
6197
+ return pack(png, options);
6198
+ };
6066
6199
 
6067
- function isnan (val) {
6068
- return val !== val // eslint-disable-line no-self-compare
6069
- }
6200
+ let util = require$$0__default["default"];
6201
+ let Stream = require$$1__default["default"];
6202
+ let Parser = parserAsync.exports;
6203
+ let Packer = packerAsync.exports;
6204
+ let PNGSync = pngSync;
6070
6205
 
6206
+ let PNG = (png.PNG = function (options) {
6207
+ Stream.call(this);
6071
6208
 
6072
- // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
6073
- // The _isBuffer check is for Safari 5-7 support, because it's missing
6074
- // Object.prototype.constructor. Remove this eventually
6075
- function isBuffer(obj) {
6076
- return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
6077
- }
6209
+ options = options || {}; // eslint-disable-line no-param-reassign
6078
6210
 
6079
- function isFastBuffer (obj) {
6080
- return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
6081
- }
6211
+ // coerce pixel dimensions to integers (also coerces undefined -> 0):
6212
+ this.width = options.width | 0;
6213
+ this.height = options.height | 0;
6082
6214
 
6083
- // For Node v0.10 support. Remove this eventually.
6084
- function isSlowBuffer (obj) {
6085
- return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
6086
- }
6215
+ this.data =
6216
+ this.width > 0 && this.height > 0
6217
+ ? Buffer.alloc(4 * this.width * this.height)
6218
+ : null;
6087
6219
 
6088
- const fs = require('fs');
6089
- const PNG = require('pngjs').PNG;
6090
- const Utils$1 = require('./utils');
6220
+ if (options.fill && this.data) {
6221
+ this.data.fill(0);
6222
+ }
6091
6223
 
6092
- exports.render = function render (qrData, options) {
6093
- const opts = Utils$1.getOptions(options);
6094
- const pngOpts = opts.rendererOpts;
6095
- const size = Utils$1.getImageWidth(qrData.modules.size, opts);
6224
+ this.gamma = 0;
6225
+ this.readable = this.writable = true;
6096
6226
 
6097
- pngOpts.width = size;
6098
- pngOpts.height = size;
6227
+ this._parser = new Parser(options);
6099
6228
 
6100
- const pngImage = new PNG(pngOpts);
6101
- Utils$1.qrToImageData(pngImage.data, qrData, opts);
6229
+ this._parser.on("error", this.emit.bind(this, "error"));
6230
+ this._parser.on("close", this._handleClose.bind(this));
6231
+ this._parser.on("metadata", this._metadata.bind(this));
6232
+ this._parser.on("gamma", this._gamma.bind(this));
6233
+ this._parser.on(
6234
+ "parsed",
6235
+ function (data) {
6236
+ this.data = data;
6237
+ this.emit("parsed", data);
6238
+ }.bind(this)
6239
+ );
6102
6240
 
6103
- return pngImage
6104
- };
6241
+ this._packer = new Packer(options);
6242
+ this._packer.on("data", this.emit.bind(this, "data"));
6243
+ this._packer.on("end", this.emit.bind(this, "end"));
6244
+ this._parser.on("close", this._handleClose.bind(this));
6245
+ this._packer.on("error", this.emit.bind(this, "error"));
6246
+ });
6247
+ util.inherits(PNG, Stream);
6105
6248
 
6106
- exports.renderToDataURL = function renderToDataURL (qrData, options, cb) {
6107
- if (typeof cb === 'undefined') {
6108
- cb = options;
6109
- options = undefined;
6249
+ PNG.sync = PNGSync;
6250
+
6251
+ PNG.prototype.pack = function () {
6252
+ if (!this.data || !this.data.length) {
6253
+ this.emit("error", "No data provided");
6254
+ return this;
6110
6255
  }
6111
6256
 
6112
- exports.renderToBuffer(qrData, options, function (err, output) {
6113
- if (err) cb(err);
6114
- let url = 'data:image/png;base64,';
6115
- url += output.toString('base64');
6116
- cb(null, url);
6117
- });
6257
+ process.nextTick(
6258
+ function () {
6259
+ this._packer.pack(this.data, this.width, this.height, this.gamma);
6260
+ }.bind(this)
6261
+ );
6262
+
6263
+ return this;
6118
6264
  };
6119
6265
 
6120
- exports.renderToBuffer = function renderToBuffer (qrData, options, cb) {
6121
- if (typeof cb === 'undefined') {
6122
- cb = options;
6123
- options = undefined;
6266
+ PNG.prototype.parse = function (data, callback) {
6267
+ if (callback) {
6268
+ let onParsed, onError;
6269
+
6270
+ onParsed = function (parsedData) {
6271
+ this.removeListener("error", onError);
6272
+
6273
+ this.data = parsedData;
6274
+ callback(null, this);
6275
+ }.bind(this);
6276
+
6277
+ onError = function (err) {
6278
+ this.removeListener("parsed", onParsed);
6279
+
6280
+ callback(err, null);
6281
+ }.bind(this);
6282
+
6283
+ this.once("parsed", onParsed);
6284
+ this.once("error", onError);
6124
6285
  }
6125
6286
 
6126
- const png = exports.render(qrData, options);
6127
- const buffer = [];
6287
+ this.end(data);
6288
+ return this;
6289
+ };
6128
6290
 
6129
- png.on('error', cb);
6291
+ PNG.prototype.write = function (data) {
6292
+ this._parser.write(data);
6293
+ return true;
6294
+ };
6130
6295
 
6131
- png.on('data', function (data) {
6132
- buffer.push(data);
6133
- });
6296
+ PNG.prototype.end = function (data) {
6297
+ this._parser.end(data);
6298
+ };
6134
6299
 
6135
- png.on('end', function () {
6136
- cb(null, Buffer.concat(buffer));
6137
- });
6300
+ PNG.prototype._metadata = function (metadata) {
6301
+ this.width = metadata.width;
6302
+ this.height = metadata.height;
6138
6303
 
6139
- png.pack();
6304
+ this.emit("metadata", metadata);
6140
6305
  };
6141
6306
 
6142
- exports.renderToFile = function renderToFile (path, qrData, options, cb) {
6143
- if (typeof cb === 'undefined') {
6144
- cb = options;
6145
- options = undefined;
6307
+ PNG.prototype._gamma = function (gamma) {
6308
+ this.gamma = gamma;
6309
+ };
6310
+
6311
+ PNG.prototype._handleClose = function () {
6312
+ if (!this._parser.writable && !this._packer.readable) {
6313
+ this.emit("close");
6146
6314
  }
6315
+ };
6147
6316
 
6148
- let called = false;
6149
- const done = (...args) => {
6150
- if (called) return
6151
- called = true;
6152
- cb.apply(null, args);
6153
- };
6154
- const stream = fs.createWriteStream(path);
6317
+ PNG.bitblt = function (src, dst, srcX, srcY, width, height, deltaX, deltaY) {
6318
+ // eslint-disable-line max-params
6319
+ // coerce pixel dimensions to integers (also coerces undefined -> 0):
6320
+ /* eslint-disable no-param-reassign */
6321
+ srcX |= 0;
6322
+ srcY |= 0;
6323
+ width |= 0;
6324
+ height |= 0;
6325
+ deltaX |= 0;
6326
+ deltaY |= 0;
6327
+ /* eslint-enable no-param-reassign */
6155
6328
 
6156
- stream.on('error', done);
6157
- stream.on('close', done);
6329
+ if (
6330
+ srcX > src.width ||
6331
+ srcY > src.height ||
6332
+ srcX + width > src.width ||
6333
+ srcY + height > src.height
6334
+ ) {
6335
+ throw new Error("bitblt reading outside image");
6336
+ }
6337
+
6338
+ if (
6339
+ deltaX > dst.width ||
6340
+ deltaY > dst.height ||
6341
+ deltaX + width > dst.width ||
6342
+ deltaY + height > dst.height
6343
+ ) {
6344
+ throw new Error("bitblt writing outside image");
6345
+ }
6158
6346
 
6159
- exports.renderToFileStream(stream, qrData, options);
6347
+ for (let y = 0; y < height; y++) {
6348
+ src.data.copy(
6349
+ dst.data,
6350
+ ((deltaY + y) * dst.width + deltaX) << 2,
6351
+ ((srcY + y) * src.width + srcX) << 2,
6352
+ ((srcY + y) * src.width + srcX + width) << 2
6353
+ );
6354
+ }
6160
6355
  };
6161
6356
 
6162
- exports.renderToFileStream = function renderToFileStream (stream, qrData, options) {
6163
- const png = exports.render(qrData, options);
6164
- png.pack().pipe(stream);
6357
+ PNG.prototype.bitblt = function (
6358
+ dst,
6359
+ srcX,
6360
+ srcY,
6361
+ width,
6362
+ height,
6363
+ deltaX,
6364
+ deltaY
6365
+ ) {
6366
+ // eslint-disable-line max-params
6367
+
6368
+ PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
6369
+ return this;
6165
6370
  };
6166
6371
 
6167
- var png = /*#__PURE__*/Object.freeze({
6168
- __proto__: null
6169
- });
6372
+ PNG.adjustGamma = function (src) {
6373
+ if (src.gamma) {
6374
+ for (let y = 0; y < src.height; y++) {
6375
+ for (let x = 0; x < src.width; x++) {
6376
+ let idx = (src.width * y + x) << 2;
6170
6377
 
6171
- var require$$2 = /*@__PURE__*/getAugmentedNamespace(png);
6378
+ for (let i = 0; i < 3; i++) {
6379
+ let sample = src.data[idx + i] / 255;
6380
+ sample = Math.pow(sample, 1 / 2.2 / src.gamma);
6381
+ src.data[idx + i] = Math.round(sample * 255);
6382
+ }
6383
+ }
6384
+ }
6385
+ src.gamma = 0;
6386
+ }
6387
+ };
6172
6388
 
6173
- var utf8 = {};
6389
+ PNG.prototype.adjustGamma = function () {
6390
+ PNG.adjustGamma(this);
6391
+ };
6174
6392
 
6175
6393
  var utils = {};
6176
6394
 
@@ -6276,14 +6494,88 @@ var utils = {};
6276
6494
  };
6277
6495
  } (utils));
6278
6496
 
6279
- var _polyfillNode_fs = {};
6497
+ (function (exports) {
6498
+ const fs = require$$1__default$2["default"];
6499
+ const PNG = png.PNG;
6500
+ const Utils = utils;
6280
6501
 
6281
- var _polyfillNode_fs$1 = /*#__PURE__*/Object.freeze({
6282
- __proto__: null,
6283
- 'default': _polyfillNode_fs
6284
- });
6502
+ exports.render = function render (qrData, options) {
6503
+ const opts = Utils.getOptions(options);
6504
+ const pngOpts = opts.rendererOpts;
6505
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
6506
+
6507
+ pngOpts.width = size;
6508
+ pngOpts.height = size;
6509
+
6510
+ const pngImage = new PNG(pngOpts);
6511
+ Utils.qrToImageData(pngImage.data, qrData, opts);
6512
+
6513
+ return pngImage
6514
+ };
6515
+
6516
+ exports.renderToDataURL = function renderToDataURL (qrData, options, cb) {
6517
+ if (typeof cb === 'undefined') {
6518
+ cb = options;
6519
+ options = undefined;
6520
+ }
6521
+
6522
+ exports.renderToBuffer(qrData, options, function (err, output) {
6523
+ if (err) cb(err);
6524
+ let url = 'data:image/png;base64,';
6525
+ url += output.toString('base64');
6526
+ cb(null, url);
6527
+ });
6528
+ };
6529
+
6530
+ exports.renderToBuffer = function renderToBuffer (qrData, options, cb) {
6531
+ if (typeof cb === 'undefined') {
6532
+ cb = options;
6533
+ options = undefined;
6534
+ }
6535
+
6536
+ const png = exports.render(qrData, options);
6537
+ const buffer = [];
6538
+
6539
+ png.on('error', cb);
6540
+
6541
+ png.on('data', function (data) {
6542
+ buffer.push(data);
6543
+ });
6544
+
6545
+ png.on('end', function () {
6546
+ cb(null, Buffer.concat(buffer));
6547
+ });
6285
6548
 
6286
- var require$$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_fs$1);
6549
+ png.pack();
6550
+ };
6551
+
6552
+ exports.renderToFile = function renderToFile (path, qrData, options, cb) {
6553
+ if (typeof cb === 'undefined') {
6554
+ cb = options;
6555
+ options = undefined;
6556
+ }
6557
+
6558
+ let called = false;
6559
+ const done = (...args) => {
6560
+ if (called) return
6561
+ called = true;
6562
+ cb.apply(null, args);
6563
+ };
6564
+ const stream = fs.createWriteStream(path);
6565
+
6566
+ stream.on('error', done);
6567
+ stream.on('close', done);
6568
+
6569
+ exports.renderToFileStream(stream, qrData, options);
6570
+ };
6571
+
6572
+ exports.renderToFileStream = function renderToFileStream (stream, qrData, options) {
6573
+ const png = exports.render(qrData, options);
6574
+ png.pack().pipe(stream);
6575
+ };
6576
+ } (png$1));
6577
+
6578
+ var utf8 = {};
6287
6579
 
6288
6580
  (function (exports) {
6289
6581
  const Utils = utils;
@@ -6353,7 +6645,7 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_fs$1);
6353
6645
  options = undefined;
6354
6646
  }
6355
6647
 
6356
- const fs = require$$1;
6648
+ const fs = require$$1__default$2["default"];
6357
6649
  const utf8 = exports.render(qrData, options);
6358
6650
  fs.writeFile(path, utf8, cb);
6359
6651
  };
@@ -6596,7 +6888,7 @@ svgTag.render = function render (qrData, options, cb) {
6596
6888
  options = undefined;
6597
6889
  }
6598
6890
 
6599
- const fs = require$$1;
6891
+ const fs = require$$1__default$2["default"];
6600
6892
  const svgTag = exports.render(qrData, options);
6601
6893
 
6602
6894
  const xmlStr = '<?xml version="1.0" encoding="utf-8"?>' +
@@ -6769,7 +7061,7 @@ function requireBrowser () {
6769
7061
 
6770
7062
  const canPromise = canPromise$1;
6771
7063
  const QRCode$1 = qrcode;
6772
- const PngRenderer = require$$2;
7064
+ const PngRenderer = png$1;
6773
7065
  const Utf8Renderer = utf8;
6774
7066
  const TerminalRenderer = terminal$1;
6775
7067
  const SvgRenderer = svg;