nftychat-universe 0.1.4 → 0.1.6

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