@hiroosy/baileys-lite 0.0.4 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +658 -10
  3. package/WAProto/index.js +2 -2558
  4. package/engine-requirements.js +3 -4
  5. package/package.json +8 -3
  6. package/src/binary/wa-binary.js +3 -25
  7. package/src/constants.js +7 -15
  8. package/src/defaults.js +2 -5
  9. package/src/foundation/ai-rich.js +530 -0
  10. package/src/foundation/audio-duration.js +43 -103
  11. package/src/foundation/audio-samples.js +19 -37
  12. package/src/foundation/boom.js +0 -7
  13. package/src/foundation/cache.js +4 -26
  14. package/src/foundation/concurrency.js +1 -19
  15. package/src/foundation/curve25519.js +7 -39
  16. package/src/foundation/link-preview.js +15 -57
  17. package/src/foundation/logger.js +0 -11
  18. package/src/foundation/long.js +4 -14
  19. package/src/foundation/protobuf-minimal.js +21 -53
  20. package/src/foundation/qrcode-terminal.js +273 -0
  21. package/src/foundation/sql-database.js +716 -0
  22. package/src/foundation/wa-crypto.js +2 -31
  23. package/src/foundation/zip.js +25 -41
  24. package/src/index.js +8 -18
  25. package/src/signal/libsignal.js +23 -78
  26. package/src/signal/signal-group.js +0 -35
  27. package/src/signal/signal-repository.js +10 -29
  28. package/src/socket/business-communities.js +12 -31
  29. package/src/socket/chats.js +5 -8
  30. package/src/socket/groups-newsletter.js +18 -17
  31. package/src/socket/messages-recv.js +81 -127
  32. package/src/socket/messages-send.js +372 -139
  33. package/src/socket/socket-core.js +227 -157
  34. package/src/socket/usync.js +2 -6
  35. package/src/socket-client/native-websocket.js +344 -0
  36. package/src/socket-client/websocket-client.js +84 -38
  37. package/src/utils/auth-state-core.js +14 -56
  38. package/src/utils/auth-state-storage.js +7 -42
  39. package/src/utils/chat-sync.js +4 -26
  40. package/src/utils/media.js +15 -71
  41. package/src/utils/message-compose.js +208 -85
  42. package/src/utils/message-processing.js +10 -65
  43. package/src/utils/username.js +19 -0
  44. package/src/utils/wa-protocol-core.js +71 -127
  45. package/src/vendor/jpeg-js/decoder.js +75 -136
  46. package/src/vendor/jpeg-js/encoder.js +179 -264
  47. package/src/vendor/pngjs/bitmapper.js +5 -27
  48. package/src/vendor/pngjs/bitpacker.js +4 -12
  49. package/src/vendor/pngjs/constants.js +3 -11
  50. package/src/vendor/pngjs/crc.js +0 -6
  51. package/src/vendor/pngjs/filter-pack.js +1 -7
  52. package/src/vendor/pngjs/filter-parse-sync.js +0 -6
  53. package/src/vendor/pngjs/filter-parse.js +1 -11
  54. package/src/vendor/pngjs/format-normaliser.js +5 -11
  55. package/src/vendor/pngjs/interlace.js +7 -24
  56. package/src/vendor/pngjs/packer-sync.js +0 -11
  57. package/src/vendor/pngjs/packer.js +7 -15
  58. package/src/vendor/pngjs/paeth-predictor.js +0 -6
  59. package/src/vendor/pngjs/parser-sync.js +0 -8
  60. package/src/vendor/pngjs/parser.js +5 -29
  61. package/src/vendor/pngjs/png-sync.js +0 -7
  62. package/src/vendor/pngjs/sync-inflate.js +7 -16
  63. package/src/vendor/pngjs/sync-reader.js +4 -11
  64. package/src/voip/WaVoipCoordinator.js +158 -0
  65. package/src/voip/app-data/WaAppDataStream.js +193 -0
  66. package/src/voip/app-data/protocol.js +172 -0
  67. package/src/voip/bytes.js +63 -0
  68. package/src/voip/call/WaCallManager.js +442 -0
  69. package/src/voip/call/WaCallMediaSession.js +1705 -0
  70. package/src/voip/call/call-state.js +203 -0
  71. package/src/voip/crypto/encryption.js +13 -0
  72. package/src/voip/crypto/primitives.js +21 -0
  73. package/src/voip/crypto/rtcp.js +66 -0
  74. package/src/voip/crypto/srtp.js +180 -0
  75. package/src/voip/crypto/ssrc.js +15 -0
  76. package/src/voip/index.js +628 -0
  77. package/src/voip/media/WaAudioEngine.js +486 -0
  78. package/src/voip/media/WaVideoEngine.js +275 -0
  79. package/src/voip/media/audio-codec.js +0 -0
  80. package/src/voip/media/audio-reorder.js +107 -0
  81. package/src/voip/media/h264.js +246 -0
  82. package/src/voip/media/mlow-codec.js +465 -0
  83. package/src/voip/media/rtcp.js +68 -0
  84. package/src/voip/media/rtp.js +242 -0
  85. package/src/voip/protobuf.js +30 -0
  86. package/src/voip/relay/WaManualRelay.js +609 -0
  87. package/src/voip/relay/datachannel/pre-negotiated.js +25 -0
  88. package/src/voip/relay/dtls/aead.js +46 -0
  89. package/src/voip/relay/dtls/cert-builder.js +102 -0
  90. package/src/voip/relay/dtls/der.js +98 -0
  91. package/src/voip/relay/dtls/ecdhe.js +37 -0
  92. package/src/voip/relay/dtls/handshake-framing.js +100 -0
  93. package/src/voip/relay/dtls/handshake-messages.js +158 -0
  94. package/src/voip/relay/dtls/handshake.js +582 -0
  95. package/src/voip/relay/dtls/prf.js +39 -0
  96. package/src/voip/relay/dtls/record.js +56 -0
  97. package/src/voip/relay/relay-ack.js +141 -0
  98. package/src/voip/relay/sctp/association.js +434 -0
  99. package/src/voip/relay/sctp/crc32c.js +21 -0
  100. package/src/voip/relay/sctp/wire.js +226 -0
  101. package/src/voip/relay/stun.js +463 -0
  102. package/src/voip/shim/baileys-resolve.js +7 -0
  103. package/src/voip/shim/core.js +66 -0
  104. package/src/voip/shim/crypto.js +6 -0
  105. package/src/voip/shim/proto.js +10 -0
  106. package/src/voip/shim/protocol.js +130 -0
  107. package/src/voip/shim/transport.js +82 -0
  108. package/src/voip/shim/util.js +207 -0
  109. package/src/voip/signaling/bridge.js +102 -0
  110. package/src/voip/signaling/screen-share.js +60 -0
  111. package/src/voip/signaling/signaling.js +491 -0
  112. package/src/voip/types.js +69 -0
  113. package/src/voip/voip-deps.js +243 -0
  114. package/src/voip/voipClient.js +314 -0
  115. package/src/wam/wam-constants.js +0 -1
  116. package/src/wam/wam.js +2 -7
@@ -1,19 +1,11 @@
1
- /**
2
- * Raw scanline bytes -> flat RGBA pixel buffer (all bit depths, palette handled upstream).
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export. See ./LICENSE.
4
- * Algorithm body unchanged vs. upstream md5 682312e25be1cfee14b102e855adbeea.
5
- * https://github.com/pngjs/pngjs
6
- */
7
1
  "use strict";
8
2
 
9
3
  import * as interlaceUtils from './interlace.js'
10
4
 
11
5
  let pixelBppMapper = [
12
- // 0 - dummy entry
6
+
13
7
  function () {},
14
8
 
15
- // 1 - L
16
- // 0: 0, 1: 0, 2: 0, 3: 0xff
17
9
  function (pxData, data, pxPos, rawPos) {
18
10
  if (rawPos === data.length) {
19
11
  throw new Error("Ran out of data");
@@ -26,8 +18,6 @@ let pixelBppMapper = [
26
18
  pxData[pxPos + 3] = 0xff;
27
19
  },
28
20
 
29
- // 2 - LA
30
- // 0: 0, 1: 0, 2: 0, 3: 1
31
21
  function (pxData, data, pxPos, rawPos) {
32
22
  if (rawPos + 1 >= data.length) {
33
23
  throw new Error("Ran out of data");
@@ -40,8 +30,6 @@ let pixelBppMapper = [
40
30
  pxData[pxPos + 3] = data[rawPos + 1];
41
31
  },
42
32
 
43
- // 3 - RGB
44
- // 0: 0, 1: 1, 2: 2, 3: 0xff
45
33
  function (pxData, data, pxPos, rawPos) {
46
34
  if (rawPos + 2 >= data.length) {
47
35
  throw new Error("Ran out of data");
@@ -53,8 +41,6 @@ let pixelBppMapper = [
53
41
  pxData[pxPos + 3] = 0xff;
54
42
  },
55
43
 
56
- // 4 - RGBA
57
- // 0: 0, 1: 1, 2: 2, 3: 3
58
44
  function (pxData, data, pxPos, rawPos) {
59
45
  if (rawPos + 3 >= data.length) {
60
46
  throw new Error("Ran out of data");
@@ -68,11 +54,9 @@ let pixelBppMapper = [
68
54
  ];
69
55
 
70
56
  let pixelBppCustomMapper = [
71
- // 0 - dummy entry
57
+
72
58
  function () {},
73
59
 
74
- // 1 - L
75
- // 0: 0, 1: 0, 2: 0, 3: 0xff
76
60
  function (pxData, pixelData, pxPos, maxBit) {
77
61
  let pixel = pixelData[0];
78
62
  pxData[pxPos] = pixel;
@@ -81,8 +65,6 @@ let pixelBppCustomMapper = [
81
65
  pxData[pxPos + 3] = maxBit;
82
66
  },
83
67
 
84
- // 2 - LA
85
- // 0: 0, 1: 0, 2: 0, 3: 1
86
68
  function (pxData, pixelData, pxPos) {
87
69
  let pixel = pixelData[0];
88
70
  pxData[pxPos] = pixel;
@@ -91,8 +73,6 @@ let pixelBppCustomMapper = [
91
73
  pxData[pxPos + 3] = pixelData[1];
92
74
  },
93
75
 
94
- // 3 - RGB
95
- // 0: 0, 1: 1, 2: 2, 3: 0xff
96
76
  function (pxData, pixelData, pxPos, maxBit) {
97
77
  pxData[pxPos] = pixelData[0];
98
78
  pxData[pxPos + 1] = pixelData[1];
@@ -100,8 +80,6 @@ let pixelBppCustomMapper = [
100
80
  pxData[pxPos + 3] = maxBit;
101
81
  },
102
82
 
103
- // 4 - RGBA
104
- // 0: 0, 1: 1, 2: 2, 3: 3
105
83
  function (pxData, pixelData, pxPos) {
106
84
  pxData[pxPos] = pixelData[0];
107
85
  pxData[pxPos + 1] = pixelData[1];
@@ -176,7 +154,7 @@ function bitRetriever(data, depth) {
176
154
  }
177
155
 
178
156
  function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
179
- // eslint-disable-line max-params
157
+
180
158
  let imageWidth = image.width;
181
159
  let imageHeight = image.height;
182
160
  let imagePass = image.index;
@@ -184,14 +162,14 @@ function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
184
162
  for (let x = 0; x < imageWidth; x++) {
185
163
  let pxPos = getPxPos(x, y, imagePass);
186
164
  pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
187
- rawPos += bpp; //eslint-disable-line no-param-reassign
165
+ rawPos += bpp;
188
166
  }
189
167
  }
190
168
  return rawPos;
191
169
  }
192
170
 
193
171
  function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
194
- // eslint-disable-line max-params
172
+
195
173
  let imageWidth = image.width;
196
174
  let imageHeight = image.height;
197
175
  let imagePass = image.index;
@@ -1,10 +1,3 @@
1
- /**
2
- * Converts a raw RGBA(16) buffer into the exact color-type/bit-depth layout the encoder will filter+deflate.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export
4
- * (zlib/util/assert/buffer -> node: specifiers). See ./LICENSE.
5
- * Algorithm body unchanged vs. upstream md5 6983b6f4ffa73ed0a734ebd0fc56c46a.
6
- * https://github.com/pngjs/pngjs
7
- */
8
1
  "use strict";
9
2
 
10
3
  import constants from './constants.js'
@@ -17,17 +10,16 @@ const bitPacker = function (dataIn, width, height, options) {
17
10
  if (options.colorType === options.inputColorType) {
18
11
  let bigEndian = (function () {
19
12
  let buffer = new ArrayBuffer(2);
20
- new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
21
- // Int16Array uses the platform's endianness.
13
+ new DataView(buffer).setInt16(0, 256, true );
14
+
22
15
  return new Int16Array(buffer)[0] !== 256;
23
16
  })();
24
- // If no need to convert to grayscale and alpha is present/absent in both, take a fast route
17
+
25
18
  if (options.bitDepth === 8 || (options.bitDepth === 16 && bigEndian)) {
26
19
  return dataIn;
27
20
  }
28
21
  }
29
22
 
30
- // map to a UInt16 array if data is 16bit, fix endianness below
31
23
  let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
32
24
 
33
25
  let maxValue = 255;
@@ -137,7 +129,7 @@ const bitPacker = function (dataIn, width, height, options) {
137
129
  break;
138
130
  case constants.COLORTYPE_ALPHA:
139
131
  case constants.COLORTYPE_GRAYSCALE: {
140
- // Convert to grayscale and alpha
132
+
141
133
  let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
142
134
  if (options.bitDepth === 8) {
143
135
  outData[outIndex] = grayscale;
@@ -1,9 +1,3 @@
1
- /**
2
- * PNG constants (chunk type codes, color-type/bpp map, signature).
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export. See ./LICENSE.
4
- * Algorithm body unchanged vs. upstream md5 4c253cc05421db7bc712c71848becdaf.
5
- * https://github.com/pngjs/pngjs
6
- */
7
1
  "use strict";
8
2
 
9
3
  export default {
@@ -13,16 +7,14 @@ export default {
13
7
  TYPE_IEND: 0x49454e44,
14
8
  TYPE_IDAT: 0x49444154,
15
9
  TYPE_PLTE: 0x504c5445,
16
- TYPE_tRNS: 0x74524e53, // eslint-disable-line camelcase
17
- TYPE_gAMA: 0x67414d41, // eslint-disable-line camelcase
10
+ TYPE_tRNS: 0x74524e53,
11
+ TYPE_gAMA: 0x67414d41,
18
12
 
19
- // color-type bits
20
13
  COLORTYPE_GRAYSCALE: 0,
21
14
  COLORTYPE_PALETTE: 1,
22
15
  COLORTYPE_COLOR: 2,
23
- COLORTYPE_ALPHA: 4, // e.g. grayscale and alpha
16
+ COLORTYPE_ALPHA: 4,
24
17
 
25
- // color-type combinations
26
18
  COLORTYPE_PALETTE_COLOR: 3,
27
19
  COLORTYPE_COLOR_ALPHA: 6,
28
20
 
@@ -1,9 +1,3 @@
1
- /**
2
- * Streaming + static CRC-32 calculator for PNG chunk checksums.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export. See ./LICENSE.
4
- * Algorithm body unchanged vs. upstream md5 5c5c1edffe5de2d22469f6a49e31dcce.
5
- * https://github.com/pngjs/pngjs
6
- */
7
1
  "use strict";
8
2
 
9
3
  let crcTable = [];
@@ -1,9 +1,3 @@
1
- /**
2
- * Applies PNG scanline filters during encode, picking the best filter per row by sum-of-abs heuristic.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export. See ./LICENSE.
4
- * Algorithm body unchanged vs. upstream md5 5e371b5b268f253d3b1e3ffc81c2731b.
5
- * https://github.com/pngjs/pngjs
6
- */
7
1
  "use strict";
8
2
 
9
3
  import paethPredictor from './paeth-predictor.js'
@@ -155,7 +149,7 @@ const filterData = function (pxData, width, height, options, bpp) {
155
149
 
156
150
  for (let y = 0; y < height; y++) {
157
151
  if (filterTypes.length > 1) {
158
- // find best filter for this line (with lowest sum of values)
152
+
159
153
  let min = Infinity;
160
154
 
161
155
  for (let i = 0; i < filterTypes.length; i++) {
@@ -1,9 +1,3 @@
1
- /**
2
- * Synchronous driver for filter-parse.js: unfilters a whole IDAT buffer at once.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export. See ./LICENSE.
4
- * Algorithm body unchanged vs. upstream md5 6b0d6b55fd9979ecf821a282c4310756.
5
- * https://github.com/pngjs/pngjs
6
- */
7
1
  "use strict";
8
2
 
9
3
  import SyncReader from './sync-reader.js'
@@ -1,9 +1,3 @@
1
- /**
2
- * Reverses PNG scanline filters (None/Sub/Up/Average/Paeth) during decode.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export. See ./LICENSE.
4
- * Algorithm body unchanged vs. upstream md5 895c8fa775fd9cab2d41a4e57f1d3948.
5
- * https://github.com/pngjs/pngjs
6
- */
7
1
  "use strict";
8
2
 
9
3
  import * as interlaceUtils from './interlace.js'
@@ -47,10 +41,6 @@ let Filter = function (bitmapInfo, dependencies) {
47
41
  });
48
42
  }
49
43
 
50
- // when filtering the line we look at the pixel to the left
51
- // the spec also says it is done on a byte level regardless of the number of pixels
52
- // so if the depth is byte compatible (8 or 16) we subtract the bpp in order to compare back
53
- // a pixel rather than just a different byte part. However if we are sub byte, we ignore.
54
44
  if (depth === 8) {
55
45
  this._xComparison = bpp;
56
46
  } else if (depth === 16) {
@@ -174,7 +164,7 @@ Filter.prototype._reverseFilterLine = function (rawData) {
174
164
  }
175
165
 
176
166
  if (currentImage) {
177
- // read, using the byte width that may be from the new current image
167
+
178
168
  this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
179
169
  } else {
180
170
  this._lastLine = null;
@@ -1,14 +1,8 @@
1
- /**
2
- * De-palettizes, applies tRNS transparency, and rescales <8-bit / 16-bit samples to 8-bit RGBA.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export. See ./LICENSE.
4
- * Algorithm body unchanged vs. upstream md5 99537bc853caf0ed8677477ac8781e6b.
5
- * https://github.com/pngjs/pngjs
6
- */
7
1
  "use strict";
8
2
 
9
3
  function dePalette(indata, outdata, width, height, palette) {
10
4
  let pxPos = 0;
11
- // use values from palette
5
+
12
6
  for (let y = 0; y < height; y++) {
13
7
  for (let x = 0; x < width; x++) {
14
8
  let color = palette[indata[pxPos]];
@@ -77,18 +71,18 @@ const formatNormaliser = function (indata, imageData, skipRescale = false) {
77
71
  let transColor = imageData.transColor;
78
72
  let palette = imageData.palette;
79
73
 
80
- let outdata = indata; // only different for 16 bits
74
+ let outdata = indata;
81
75
 
82
76
  if (colorType === 3) {
83
- // paletted
77
+
84
78
  dePalette(indata, outdata, width, height, palette);
85
79
  } else {
86
80
  if (transColor) {
87
81
  replaceTransparentColor(indata, outdata, width, height, transColor);
88
82
  }
89
- // if it needs scaling
83
+
90
84
  if (depth !== 8 && !skipRescale) {
91
- // if we need to change the buffer size
85
+
92
86
  if (depth === 16) {
93
87
  outdata = Buffer.alloc(width * height * 4);
94
88
  }
@@ -1,55 +1,38 @@
1
- /**
2
- * Adam7 interlacing: pass geometry + per-pixel position iterator.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export. See ./LICENSE.
4
- * Algorithm body unchanged vs. upstream md5 5b88af15956679350faec79a91ec6c17.
5
- * https://github.com/pngjs/pngjs
6
- */
7
1
  "use strict";
8
2
 
9
- // Adam 7
10
- // 0 1 2 3 4 5 6 7
11
- // 0 x 6 4 6 x 6 4 6
12
- // 1 7 7 7 7 7 7 7 7
13
- // 2 5 6 5 6 5 6 5 6
14
- // 3 7 7 7 7 7 7 7 7
15
- // 4 3 6 4 6 3 6 4 6
16
- // 5 7 7 7 7 7 7 7 7
17
- // 6 5 6 5 6 5 6 5 6
18
- // 7 7 7 7 7 7 7 7 7
19
-
20
3
  let imagePasses = [
21
4
  {
22
- // pass 1 - 1px
5
+
23
6
  x: [0],
24
7
  y: [0],
25
8
  },
26
9
  {
27
- // pass 2 - 1px
10
+
28
11
  x: [4],
29
12
  y: [0],
30
13
  },
31
14
  {
32
- // pass 3 - 2px
15
+
33
16
  x: [0, 4],
34
17
  y: [4],
35
18
  },
36
19
  {
37
- // pass 4 - 4px
20
+
38
21
  x: [2, 6],
39
22
  y: [0, 4],
40
23
  },
41
24
  {
42
- // pass 5 - 8px
25
+
43
26
  x: [0, 2, 4, 6],
44
27
  y: [2, 6],
45
28
  },
46
29
  {
47
- // pass 6 - 16px
30
+
48
31
  x: [1, 3, 5, 7],
49
32
  y: [0, 2, 4, 6],
50
33
  },
51
34
  {
52
- // pass 7 - 32px
35
+
53
36
  x: [0, 1, 2, 3, 4, 5, 6, 7],
54
37
  y: [1, 3, 5, 7],
55
38
  },
@@ -1,10 +1,3 @@
1
- /**
2
- * Synchronous whole-buffer PNG encode entry point: signature + IHDR + gAMA + deflated IDAT + IEND.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export
4
- * (zlib/util/assert/buffer -> node: specifiers). See ./LICENSE.
5
- * Algorithm body unchanged vs. upstream md5 51da0119926dab0998788987873fc853.
6
- * https://github.com/pngjs/pngjs
7
- */
8
1
  "use strict";
9
2
 
10
3
  let hasSyncZlib = true;
@@ -28,10 +21,8 @@ const packSync = function (metaData, opt) {
28
21
 
29
22
  let chunks = [];
30
23
 
31
- // Signature
32
24
  chunks.push(Buffer.from(constants.PNG_SIGNATURE));
33
25
 
34
- // Header
35
26
  chunks.push(packer.packIHDR(metaData.width, metaData.height));
36
27
 
37
28
  if (metaData.gamma) {
@@ -44,7 +35,6 @@ const packSync = function (metaData, opt) {
44
35
  metaData.height
45
36
  );
46
37
 
47
- // compress it
48
38
  let compressedData = zlib.deflateSync(
49
39
  filteredData,
50
40
  packer.getDeflateOptions()
@@ -56,7 +46,6 @@ const packSync = function (metaData, opt) {
56
46
  }
57
47
  chunks.push(packer.packIDAT(compressedData));
58
48
 
59
- // End
60
49
  chunks.push(packer.packIEND());
61
50
 
62
51
  return Buffer.concat(chunks);
@@ -1,10 +1,3 @@
1
- /**
2
- * Packer object: builds PNG chunks (IHDR/gAMA/IDAT/IEND) from pixel data using bitpacker+filter-pack+zlib.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export
4
- * (zlib/util/assert/buffer -> node: specifiers). See ./LICENSE.
5
- * Algorithm body unchanged vs. upstream md5 bb043be341ec01e2db5b765f7ee86fec.
6
- * https://github.com/pngjs/pngjs
7
- */
8
1
  "use strict";
9
2
 
10
3
  import constants from './constants.js'
@@ -25,7 +18,7 @@ let Packer = function (options) {
25
18
  options.inputHasAlpha != null ? options.inputHasAlpha : true;
26
19
  options.deflateFactory = options.deflateFactory || zlib.createDeflate;
27
20
  options.bitDepth = options.bitDepth || 8;
28
- // This is outputColorType
21
+
29
22
  options.colorType =
30
23
  typeof options.colorType === "number"
31
24
  ? options.colorType
@@ -81,10 +74,9 @@ Packer.prototype.createDeflate = function () {
81
74
  };
82
75
 
83
76
  Packer.prototype.filterData = function (data, width, height) {
84
- // convert to correct format for filtering (e.g. right bpp and bit depth)
77
+
85
78
  let packedData = bitPacker(data, width, height, this._options);
86
79
 
87
- // filter pixel data
88
80
  let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
89
81
  let filteredData = filter(packedData, width, height, this._options, bpp);
90
82
  return filteredData;
@@ -118,11 +110,11 @@ Packer.prototype.packIHDR = function (width, height) {
118
110
  let buf = Buffer.alloc(13);
119
111
  buf.writeUInt32BE(width, 0);
120
112
  buf.writeUInt32BE(height, 4);
121
- buf[8] = this._options.bitDepth; // Bit depth
122
- buf[9] = this._options.colorType; // colorType
123
- buf[10] = 0; // compression
124
- buf[11] = 0; // filter
125
- buf[12] = 0; // interlace
113
+ buf[8] = this._options.bitDepth;
114
+ buf[9] = this._options.colorType;
115
+ buf[10] = 0;
116
+ buf[11] = 0;
117
+ buf[12] = 0;
126
118
 
127
119
  return this._packChunk(constants.TYPE_IHDR, buf);
128
120
  };
@@ -1,9 +1,3 @@
1
- /**
2
- * Paeth predictor (PNG filter type 4) used by both the parser and packer.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export. See ./LICENSE.
4
- * Algorithm body unchanged vs. upstream md5 05b33c66f5c16acd9267747c40a24054.
5
- * https://github.com/pngjs/pngjs
6
- */
7
1
  "use strict";
8
2
 
9
3
  export default function paethPredictor(left, above, upLeft) {
@@ -1,10 +1,3 @@
1
- /**
2
- * Synchronous whole-buffer PNG decode entry point: parse chunks, zlib-inflate IDAT, unfilter, bitmap, normalise.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export
4
- * (zlib/util/assert/buffer -> node: specifiers). See ./LICENSE.
5
- * Algorithm body unchanged vs. upstream md5 dc170d369c632b306a208ae9527d9c5a.
6
- * https://github.com/pngjs/pngjs
7
- */
8
1
  "use strict";
9
2
 
10
3
  let hasSyncZlib = true;
@@ -78,7 +71,6 @@ const parseSync = function (buffer, options) {
78
71
  throw err;
79
72
  }
80
73
 
81
- //join together the inflate datas
82
74
  let inflateData = Buffer.concat(inflateDataList);
83
75
  inflateDataList.length = 0;
84
76
 
@@ -1,10 +1,3 @@
1
- /**
2
- * Chunk-by-chunk PNG parser state machine: IHDR/PLTE/tRNS/gAMA/IDAT/IEND handlers + CRC check.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export
4
- * (zlib/util/assert/buffer -> node: specifiers). See ./LICENSE.
5
- * Algorithm body unchanged vs. upstream md5 246405eeea384bf713721b876aecb968.
6
- * https://github.com/pngjs/pngjs
7
- */
8
1
  "use strict";
9
2
 
10
3
  import constants from './constants.js'
@@ -18,7 +11,6 @@ let Parser = function (options, dependencies) {
18
11
  this._hasIEND = false;
19
12
  this._emittedHeadersFinished = false;
20
13
 
21
- // input flags/metadata
22
14
  this._palette = [];
23
15
  this._colorType = 0;
24
16
 
@@ -60,22 +52,16 @@ Parser.prototype._parseSignature = function (data) {
60
52
  };
61
53
 
62
54
  Parser.prototype._parseChunkBegin = function (data) {
63
- // chunk content length
55
+
64
56
  let length = data.readUInt32BE(0);
65
57
 
66
- // chunk type
67
58
  let type = data.readUInt32BE(4);
68
59
  let name = "";
69
60
  for (let i = 4; i < 8; i++) {
70
61
  name += String.fromCharCode(data[i]);
71
62
  }
72
63
 
73
- //console.log('chunk ', name, length);
74
-
75
- // chunk flags
76
- let ancillary = Boolean(data[4] & 0x20); // or critical
77
- // priv = Boolean(data[5] & 0x20), // or public
78
- // safeToCopy = Boolean(data[7] & 0x20); // or unsafe
64
+ let ancillary = Boolean(data[4] & 0x20);
79
65
 
80
66
  if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
81
67
  this.error(new Error("Expected IHDR on beggining"));
@@ -97,7 +83,7 @@ Parser.prototype._parseChunkBegin = function (data) {
97
83
  this.read(length + 4, this._skipChunk.bind(this));
98
84
  };
99
85
 
100
- Parser.prototype._skipChunk = function (/*data*/) {
86
+ Parser.prototype._skipChunk = function () {
101
87
  this.read(8, this._parseChunkBegin.bind(this));
102
88
  };
103
89
 
@@ -109,7 +95,6 @@ Parser.prototype._parseChunkEnd = function (data) {
109
95
  let fileCrc = data.readInt32BE(0);
110
96
  let calcCrc = this._crc.crc32();
111
97
 
112
- // check CRC
113
98
  if (this._options.checkCRC && calcCrc !== fileCrc) {
114
99
  this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
115
100
  return;
@@ -129,16 +114,11 @@ Parser.prototype._parseIHDR = function (data) {
129
114
  let width = data.readUInt32BE(0);
130
115
  let height = data.readUInt32BE(4);
131
116
  let depth = data[8];
132
- let colorType = data[9]; // bits: 1 palette, 2 color, 4 alpha
117
+ let colorType = data[9];
133
118
  let compr = data[10];
134
119
  let filter = data[11];
135
120
  let interlace = data[12];
136
121
 
137
- // console.log(' width', width, 'height', height,
138
- // 'depth', depth, 'colorType', colorType,
139
- // 'compr', compr, 'filter', filter, 'interlace', interlace
140
- // );
141
-
142
122
  if (
143
123
  depth !== 8 &&
144
124
  depth !== 4 &&
@@ -194,7 +174,6 @@ Parser.prototype._parsePLTE = function (data) {
194
174
  this._crc.write(data);
195
175
 
196
176
  let entries = Math.floor(data.length / 3);
197
- // console.log('Palette:', entries);
198
177
 
199
178
  for (let i = 0; i < entries; i++) {
200
179
  this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 0xff]);
@@ -212,7 +191,6 @@ Parser.prototype._handleTRNS = function (length) {
212
191
  Parser.prototype._parseTRNS = function (data) {
213
192
  this._crc.write(data);
214
193
 
215
- // palette
216
194
  if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
217
195
  if (this._palette.length === 0) {
218
196
  this.error(new Error("Transparency chunk must be after palette"));
@@ -228,10 +206,8 @@ Parser.prototype._parseTRNS = function (data) {
228
206
  this.palette(this._palette);
229
207
  }
230
208
 
231
- // for colorType 0 (grayscale) and 2 (rgb)
232
- // there might be one gray/color defined as transparent
233
209
  if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
234
- // grey, 2 bytes
210
+
235
211
  this.transColor([data.readUInt16BE(0)]);
236
212
  }
237
213
  if (this._colorType === constants.COLORTYPE_COLOR) {
@@ -1,10 +1,3 @@
1
- /**
2
- * Public sync API: `read(buffer, options)` / `write(png, options)` — mirrors `pngjs`'s PNG.sync.
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export
4
- * (zlib/util/assert/buffer -> node: specifiers). See ./LICENSE.
5
- * Algorithm body unchanged vs. upstream md5 57db1eb23be674e473fa48a26b493ca7.
6
- * https://github.com/pngjs/pngjs
7
- */
8
1
  "use strict";
9
2
 
10
3
  import parse from './parser-sync.js'
@@ -1,10 +1,3 @@
1
- /**
2
- * Node-version-independent synchronous zlib inflate (wraps zlib.Inflate's internal handle directly).
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export
4
- * (zlib/util/assert/buffer -> node: specifiers). See ./LICENSE.
5
- * Algorithm body unchanged vs. upstream md5 91108ad5150178c7643155151266d812.
6
- * https://github.com/pngjs/pngjs
7
- */
8
1
  "use strict";
9
2
 
10
3
  import assertModule from 'node:assert'
@@ -25,7 +18,6 @@ function Inflate(opts) {
25
18
 
26
19
  zlib.Inflate.call(this, opts);
27
20
 
28
- // Node 8 --> 9 compatibility check
29
21
  this._offset = this._offset === undefined ? this._outOffset : this._offset;
30
22
  this._buffer = this._buffer || this._outBuffer;
31
23
 
@@ -43,7 +35,6 @@ function _close(engine, callback) {
43
35
  process.nextTick(callback);
44
36
  }
45
37
 
46
- // Caller may invoke .close after a zlib error (which will null _handle).
47
38
  if (!engine._handle) {
48
39
  return;
49
40
  }
@@ -118,14 +109,14 @@ Inflate.prototype._processChunk = function (chunk, flushFlag, asyncCb) {
118
109
  do {
119
110
  res = this._handle.writeSync(
120
111
  flushFlag,
121
- chunk, // in
122
- inOff, // in_off
123
- availInBefore, // in_len
124
- this._buffer, // out
125
- this._offset, //out_off
112
+ chunk,
113
+ inOff,
114
+ availInBefore,
115
+ this._buffer,
116
+ this._offset,
126
117
  availOutBefore
127
- ); // out_len
128
- // Node 8 --> 9 compatibility check
118
+ );
119
+
129
120
  res = res || this._writeState;
130
121
  } while (!this._hadError && handleChunk(res[0], res[1]));
131
122
 
@@ -1,10 +1,3 @@
1
- /**
2
- * Queues fixed-length read requests and satisfies them from an in-memory buffer (no real streaming).
3
- * Vendored from `pngjs` 7.0.0 (MIT). Only require()/module.exports converted to import/export
4
- * (zlib/util/assert/buffer -> node: specifiers). See ./LICENSE.
5
- * Algorithm body unchanged vs. upstream md5 2f8cd5d2a5f159a57f163a5fad634463.
6
- * https://github.com/pngjs/pngjs
7
- */
8
1
  "use strict";
9
2
 
10
3
  let SyncReader = function (buffer) {
@@ -14,14 +7,14 @@ let SyncReader = function (buffer) {
14
7
 
15
8
  SyncReader.prototype.read = function (length, callback) {
16
9
  this._reads.push({
17
- length: Math.abs(length), // if length < 0 then at most this length
10
+ length: Math.abs(length),
18
11
  allowLess: length < 0,
19
12
  func: callback,
20
13
  });
21
14
  };
22
15
 
23
16
  SyncReader.prototype.process = function () {
24
- // as long as there is any data and read requests
17
+
25
18
  while (this._reads.length > 0 && this._buffer.length) {
26
19
  let read = this._reads[0];
27
20
 
@@ -29,8 +22,8 @@ SyncReader.prototype.process = function () {
29
22
  this._buffer.length &&
30
23
  (this._buffer.length >= read.length || read.allowLess)
31
24
  ) {
32
- // ok there is any data so that we can satisfy this request
33
- this._reads.shift(); // == read
25
+
26
+ this._reads.shift();
34
27
 
35
28
  let buf = this._buffer;
36
29